4 条题解

  • 0
    @ 2023-9-2 15:32:49

    `

    #include<bits/stdc++.h>
    using namespace std;
    int a[20],n,x;
    int main()
    {
    	cin>>n;
    	for(int i=0;i<n;i++)
        {
    		cin>>a[i];
    		x=0;
    		while(a[i] != 0)
            {
    			x+=a[i]%10;
    			a[i]/=10;
    		}
    		a[i]=x;
    	}
    	sort(a,a+n);
    	for(int i=0;i<n;i++)
        {
    		cout<<a[i]<< " ";
    	} 
    	return 0;
    }
    
    • 0
      @ 2023-5-6 21:06:03
      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
          int n,a[98],b[98];
          cin >> n;
          for(int i=1;i<=n;i++)
          {
              cin >> a[i];
              b[i]=0;
              while(a[i]>0)
              {
                  b[i]+=a[i]%10;
                  a[i]/=10;
              }
          }
          sort(b+1,b+1+n);
          for(int i=1;i<=n;i++)
          {
              cout << b[i] << " ";
          }
      }
      
      • 0
        @ 2023-4-14 22:19:17

        一坨

        #include<bits/stdc++.h>
        using namespace std;
        int a[11],n;
        int main()
        {
            cin>>n;
            for (int i=1;i<=n;i++)
            {
                cin>>a[i];
                a[i]=a[i]%10+a[i]/10%10+a[i]/100%10+a[i]/1000%10+a[i]/10000;
            }
            sort(a+1,a+n+1);
            for (int i=1;i<=n;i++)
                cout<<a[i]<<" ";
            return 0;
        }
        • 0
          @ 2023-1-19 13:55:20
          #include<bits/stdc++.h>
          using namespace std;
          int a[20], n, s;
          int main()
          {
          	cin >> n;
          	int i;
          	for(i = 0; i < n; i++){
          		cin >> a[i];
          		s = 0;//每个a[i]都要求和,单独清零
          		//求a[i]的各个位的和
          		while(a[i] != 0){
          			s =  s + a[i]%10;
          			a[i] = a[i] / 10;
          		}
          		a[i] = s;
          	}
          	//排序
          	sort(a,a+n);
          	//输出
          	for(int i = 0; i < n; i++){
          		cout << a[i] << " ";
          	} 
          	return 0;
          }
          
          • 1

          信息

          ID
          166
          时间
          1000ms
          内存
          16MiB
          难度
          1
          标签
          递交数
          73
          已通过
          58
          上传者