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

5_回文平方

作者: 作者的头像   KaMtuo ,  2021-01-13 09:04:44 ,  阅读 29


0


https://www.acwing.com/problem/content/1348/

#include<bits/stdc++.h>
using namespace std;
#define change(a,b) ((a%b>=10)?(a%b-10+'A'):(a%b+'0'))
int main(){
    char ans[10000];
    char ans2[10000];
    int b;
    cin>>b;
    for(int i=1;i<=300;i++)
    {
        int j=0;
        int p=i*i;
        while(p)
        {
            ans[j++]=change(p,b);
            p/=b;
        }
        int x=strlen(ans);
        int flag=0;
        for(int f=0;f<x/2;f++)
        {
            if(ans[f]!=ans[x-1-f]){flag=1;
            break;
            }
        }
        if(!flag){
           // cout<<i<<' ';
            int p=i;
            j=0;
        while(p)
        {
            ans2[j++]=change(p,b);
            p/=b;
        }
        int y=strlen(ans2);
         for(int f=y-1;f>=0;f--)
        cout<<ans2[f];
        cout<<' '; 
        for(int f=x-1;f>=0;f--)
        cout<<ans[f];
        cout<<endl;
        }
    }
    return 0;
}

0 评论

你确定删除吗?

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