pat乙级 这题还有什么情况没考虑到

冷眼观world 冷眼观world 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下 #include <iostream>
#include <stdlib.h>
using namespace std;
int reverse(int a)
{
int ans = 0, b = 0;

while(a)
{
b = a % 10;
ans = ans * 10 + b;
a /= 10;
b = 0;
}

return ans;
}
int main()
{
int num = 0, cnt = 0;

cin >> num;
while(num != reverse(num))
{
cout << num << " + " << reverse(num) << " = " << num + reverse(num) << endl;
num = num + reverse(num);
cnt++;
if(cnt == 10)
break;
}
if(cnt == 10)
{
cout << "Not found in 10 iterations.";
} else if(num == reverse(num))
{
cout << num << " is a palindromic number.";
}

system("pause");
return 0;
}
...全文
评论 5
收藏 已收藏
分享
返回顶部
冷眼观world
C++ 语言 65,214 成员 250,514 内容