c++输入几个数,判断是否为回文数并输出运算了几次?
intfanshu(intnum){intnum1=0;while(num!=0){num1=num%10+10*num1;num=num/10;}returnnum1;...
int fanshu(int num) {
int num1=0;
while (num != 0) {
num1=num % 10+10*num1;
num = num / 10;
}
return num1;
}
void task1102() {
int ci,num,temp;
cin >> ci;
for (int i = 1; i <= ci; i++) {
cin >> num;
for (int j = 0; j <= 20; j++) {
if (num == fanshu(num)) {
cout <<j<<" "<< num << endl;
break;
}
else {
num = fanshu(num)+num;
}
if (j == 20) {
cout << "impossible" << endl;
}
}
}
}
int main() {
task1102();
return 0;
}
程序是对的,但在oj平台提交却出现了错误。 展开
int num1=0;
while (num != 0) {
num1=num % 10+10*num1;
num = num / 10;
}
return num1;
}
void task1102() {
int ci,num,temp;
cin >> ci;
for (int i = 1; i <= ci; i++) {
cin >> num;
for (int j = 0; j <= 20; j++) {
if (num == fanshu(num)) {
cout <<j<<" "<< num << endl;
break;
}
else {
num = fanshu(num)+num;
}
if (j == 20) {
cout << "impossible" << endl;
}
}
}
}
int main() {
task1102();
return 0;
}
程序是对的,但在oj平台提交却出现了错误。 展开
1个回答
展开全部
#include using namespace std; bool hui(char c[]) { int len,i,j; len=strlen(c); for(i=0,j=len-1;ij) return true; } int main() { char c[2000]; cin>>c; if(hui(c)) cout<<c<<" 是回文"<<endl; else cout<<c<<" 不是回文"<<endl; return 0; }
追问
谢谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询