AcWing
  • 首页
  • 题库
  • 题解
  • 分享
  • 问答
  • 活动
  • 应用
  • 吐槽
  • 登录/注册

AcWing 1346. 回文平方 0.06 AC币

作者: 作者的头像   YimingLi ,  2021-01-13 11:52:07 ,  阅读 15


1


#include <iostream>
#include <algorithm>
using namespace std;

int n;
string toString(int x) {
    string ans;
    while (x) {
        int remainder = x % n;
        ans += remainder >= 10 ? remainder - 10 + 'A' : remainder + '0';
        x /= n;
    }
    return ans;
}
int main() {
    cin >> n;
    for (int x = 1; x <= 300; x++) {
        int y = x * x;
        string a = toString(y), b = a;
        reverse(b.begin(), b.end());
        if(a == b) {
            string c = toString(x), d = c;
            reverse(d.begin(), d.end());
            cout << d << " " << b << endl;
        }
    }
    return 0;
}

0 评论

你确定删除吗?

© 2018-2021 AcWing 版权所有  |  京ICP备17053197号-1
联系我们  |  常见问题
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息