解题思路:
注意事项:
参考代码:
#include"bits/stdc++.h" using namespace std; int fan(int ch){ //反转 把数反转 返回num int t=ch; int num=0; while(t>0) { num = num*10 + t%10; t /= 10; } return num; } bool check(int zz){ //检查是不是回文数 是:返回true 不是:返回false int t=zz; int num=0; while(t>0) { num = num*10 + t%10; t /= 10; } if(zz== num) //判断反转后是否相等 return true; return false; } int main(){ int l; int m; cin>>l; int bushu=0; while(l){ bushu=0; cin>>m; while(1){ bushu++; fan(m); //先反转 m=fan(m)+m; //m等于其自身与其反转数的和 if(check(m)) //相加之和 如果是回文数 直接结束 break; if(bushu>8){ //步数大于8 直接结束 bushu=0; break; } } cout<<bushu<<endl; l--; } return 0; }
0.0分
0 人评分
#include"bits/stdc++.h" using namespace std; int flag=0; int fan(int ch){ //反转 把回文数反转 返回num f(n) int t=ch; int num=0; while(t>0) { num = num*10 + t%10; t /= 10; } return num; } int main(){ int l; int m; cin>>l; int bushu=0; while(l){ bushu=0; cin>>m; while(1){ bushu++; fan(m); //先反转 m=fan(m)+m; //m等于其自身与其反转数的和 if(m==fan(m)) break; if(bushu>8){ //步数大于8 直接结束 bushu=0; break; } } cout<<bushu<<endl; l