7 条题解

  • -1

    #include <iostream>
    using namespace std;
    int main()
    {
    int cnt=0,a;
    cin>>a;

    for(int x=1; x<a; x++)
    {
    int y=0;
    for(int xx=x; xx>0; xx=xx/10)
    {
    int x1=xx%10;

    y=y*10+x1;

    }

    if(x==y)
    {

    cnt++;

    }
    }
    cout<<cnt<<endl;
    return 0;
    }

  • -2

    #include <stdio.h>
    //回文数的个数
    int main ()
    {
    int i=0;
    int x,xmax,x1;

    scanf("%d",&xmax);
    for(x=1;x<xmax;x++)
    {
    //求反数
    int xx=x;
    int y=0;
    while (xx>0)
    {
    x1=xx%10;
    y=x1+y*10; xx=xx/10;

    }
    //判断是否为回文数
    if (x==y)
    i++;
    }
    printf("%d",i);
    return 0;

    }

  • -3

    #include <iostream>
    using namespace std;
    int main()
    {
    int y;
    cin>>y;
    int cnt;
    for(int x=1;x<y;x++)
    {
    int y=0;
    for(int xx=x;xx>0;xx=xx/10)
    {
    int x1=xx%10;
    y=y*10+x1;
    }

    if(x==y)
    {
    cnt++;
    }
    }
    cout<<cnt;
    return 0;

    }

  • -3

    #include <iostream>
    using namespace std;
    int main()
    {
    int cnt=0,n;
    cin>>n;

    for(int x=1; x<=n; x++)
    {
    int y=0;

    for(int xx=x; xx>0; xx=xx/10)
    {
    int x1=xx%10;

    y=y*10+x1;

    }

    if(x==y)
    {

    cnt++;

    }
    }
    cout<<cnt<<endl;
    return 0;
    }

  • -3
    @ 2019-11-19 14:22:32

    #include <stdio.h>
    //回文数的个数
    int main ()
    {
    int i=0;
    int x,xmax,x1;

    scanf("%d",&xmax);
    for(x=1;x<xmax;x++)
    {
    //求反数
    int xx=x;
    int y=0;
    while (xx>0)
    {
    x1=xx%10;
    y=x1+y*10; xx=xx/10;

    }
    //判断是否为回文数
    if (x==y)
    i++;
    }
    printf("%d",i);
    return 0;

    }

  • -3
    #include<iostream>
    #define Yes 1
    #define No -1
    using namespace std;
    class Array
    {
    private:
        int n;
        int size;
        int *a;
    public:
        Array(int set_n)
        {
            n=set_n;
            size=n*2;
            a=new int[size];
        }
    
        void set_array(int x)
        {
            int flag=0;
            while(x>=1)
            {
                a[flag]=x%10;//因为是判断回文数,所以输入顺序无所谓
                x=x/10;
                flag++;
            }
        }
    
        int judge()
        {
            int flag=(n-2)/2;//要比到的中间一个数的下标
            if(n==1)
                return Yes;
            for(int i=0;i<=flag;i++)
            {
                if(a[i]!=a[n-i-1])
                    return No;
            }
            return Yes;
        }
    
        friend int get_len(int x);        
    };
        int get_len(int x)
        {
            int len=0;
            while(x>0)
            {
                len++;
                x=x/10;
            }
            return len;
        }
    
    int main()
    {
        int x;
        cin>>x;
        int flag=0;
        
        for(int i=1;i<=x;i++)
        {
            int len=get_len(i);
            Array arr(len);
            arr.set_array(i);
            if(arr.judge()==Yes)
                flag++;
        }
        cout<<flag<<endl;
    
        system("pause");
        return 0;
    }
    
    
  • -4
    @ 2021-01-25 17:13:35

    这个题有一个很容易错的点 题目中给的数据范围【1,n】不包含n 试了几次才发现不用加等号
    下面是本人混乱的代码
    ```cpp
    #include<iostream>
    using namespace std;
    int main()
    {
    int n,xvx=0,az=0;
    cin>>n;

    for(int i=1;i<n;i++)
    {
    int n1=i;
    xvx=0;
    while(n1)
    {
    xvx=xvx*10+n1%10;
    n1/=10;
    }
    if(xvx==i)
    {
    az++;
    }
    }
    cout<<az;
    return 0;
    }
    ```

  • 1

A4-4 回文数专题:回文数个数

信息

难度
8
分类
(无)
标签
递交数
3145
已通过
276
通过率
9%
被复制
11
上传者