进制转换,然后判断是否是回文

/*******************************************
  TASK: palsquare
  LANG: C++ 
  Created Time: 2016年09月07日 星期三 21时18分46秒
 *********************************/

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

void bas(int x,int b,char ans[]){
    int i;
    for(i=0;x;i++){
        int t=x%b;
        x/=b;
        if(t>9)ans[i]=t%10+'A';
        else ans[i]=t+'0';
    }
    for(int j=0;j<i/2;j++)
    swap(ans[j],ans[i-j-1]);
}
int ispal(char s[]){
    int len=strlen(s);
    for(int i=0;i<len;i++)
        if(s[i]!=s[len-i-1])return 0;
    return 1;
}
int main(){
    freopen("palsquare.in","r",stdin);
    freopen("palsquare.out","w",stdout);
    int b;
    cin>>b;
    for(int i=1;i<=300;i++){
        char s[20];
    memset(s,0,sizeof s);
        bas(i*i,b,s);
        if(ispal(s)){
        char n[20];
        memset(n,0,sizeof n);
        bas(i,b,n);
        cout<<n<<" "<<s<<endl;
    }
    }
    return 0;
}

 

相关文章:

  • 2021-06-11
  • 2022-12-23
  • 2021-05-29
  • 2021-12-09
  • 2021-06-21
  • 2021-09-19
  • 2022-02-27
  • 2021-09-30
猜你喜欢
  • 2021-11-08
  • 2021-08-19
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2022-03-03
相关资源
相似解决方案