回文对称数#题解

回文对称数

https://ac.nowcoder.com/acm/contest/19305/1050

传送门-->>回文对称数

alt

思路;首先编写一个check函数来判断是否是回文数,然后for循环一一枚举就行了

#include <bits/stdc++.h>
using namespace std;
bool check(int x)
{
    int ans = 0;
    int res = x;
    while(x>0)
    {
        ans=ans*10+x%10;
        x/=10;
    }
    if(ans==res)return true;
    return false;
}
int main()
{
    int x;
    cin>>x;
    for(int i = 1;i < x;i++)
    {
        if(check(i)){
            cout<<i<<endl;
        }
    }
    
    return 0;
}


全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务