哈囉
很久沒看到我的發文
很期待對巴
#include<iostream> #include<string> using namespace std; int main() { string s; int j,k; int num; while (cin>>num) { int times[1001]={0}; for (k=0;k<num;k++) { cin>>s; int i=0; int check=0; while (check==0) { string s2=""; for(j=s.length()-1;j>=0;j--) { s2+=s[j]; } for (j=s.length()-1;j>=0;j--) { s[j]+=s2[j]-48; if (s[j]>'9') { s[j]-=10; if (j!=0) s[j-1]+=1; else s.insert(0,"1"); } } times[k]++; int half; half=s.length()/2; for (i=0,j=s.length()-1;i<=half;i++,j--) { if (s[i]!=s[j]) { check=0; break; } check=1; } } cout<<times[k]<<" "<<s<<endl; } } return 0; }
哈囉
很久沒看到我的發文
很期待對巴
#include #include using namespace std; int main() { string s; int j,k; int num; while (cin>>num) { int times[1001]={0}; for (k=0;k<num;k++) { cin>>s; int i=0; int check=0; while (check==0) { string s2=""; for(j=s.length()-1;j>=0;j--) { s2+=s[j]; } for (j=s.length()-1;j>=0;j--) { s[j]+=s2[j]-48; if (s[j]>'9') { s[j]-=10; if (j!=0) s[j-1]+=1; else s.insert(0,"1"); } } times[k]++; int half; half=s.length()/2; for (i=0,j=s.length()-1;i<=half;i++,j--) { if (s[i]!=s[j]) { check=0; break; } check=1; } } cout<<times[k]<<" "<<s<<endl; } } return 0; }
學長的解法好長
我的:
#include<iostream>
using namespace std;
unsigned int aaa(int a){
unsigned int b(0);
while(a!=0){
b=b*10+a%10;
a/=10;
}
return b;
}
int main(){
int b;
unsigned a;
cin>>b;
while(b--){
cin>>a;
for(int c=0;c<1000;c++){
a+=aaa(a);
if(a==aaa(a)){
cout<<c+1<<' '<<a<<endl;
break;
}
}
}
}