2 条题解

  • 1
    @ 2024-1-31 11:03:36

    这一道题是关于二维数组的,题目让我们判断二维数组中的各个元素是不是回文数,那判断回文数就简单了,先直接上数位拆分,然后根据数位个数判断各个数位是否相等,最后根据情况决定是否输出当前数组中的元素就行了这一道题难度不高,但是思维需要很缜密才能完美地做出这道题来大家先理一下思路,再上手哦~

    已AC,请放心食用

    #include <iostream>
    using namespace std;
    int n, m, a[10001], x, s, b[4];
    int main()
    {
        cin >> n >> m;
        for (int i = 0; i < n * m; i++)
        {
            cin >> a[i];
            x = a[i];
            s = 0;
            while (x > 0)
            {
                b[s] = x % 10;
                s++;
                x /= 10;
            }
            if (s == 4)
            {
                if (b[3] == b[0] && b[2] == b[1])
                {
                    cout << a[i] << endl;
                }
            }
            else if (s == 3)
            {
                if (b[2] == b[0])
                {
                    cout << a[i] << endl;
                }
            }
            else if (s == 2)
            {
                if (b[1] == b[0])
                {
                    cout << a[i] << endl;
                } 
            }
            else
            {
                cout << a[i] << endl;
            }
        }
        return 0;
    }
    

    养成好习惯,看后点个赞( •̀ ω •́ )✧!

    • 0
      @ 2023-8-4 0:36:51

      已AC,放心食用

      #include<bits/stdc++.h>
      using namespace std;
      int n,m,t,s,a;
      int main(){
          cin>>n>>m;
          for(int i=1;i<=n;i++)
              for(int j=1;j<=m;j++){
           	    cin>>t;
           	    s=0;
           	    a=t;
           	    while(t!=0){
           		    s=s*10+t%10;
           		    t/=10;
      		    }
      		    if(a==s)
      		        cout<<a<<endl;
      	    }
          return 0;
      }
      
      • 1

      信息

      ID
      400
      时间
      1000ms
      内存
      16MiB
      难度
      1
      标签
      递交数
      38
      已通过
      28
      上传者