2 条题解

  • 0
    @ 2023-10-18 11:06:08
    #include<iostream>
    #include<string>
    using namespace std;
    int main()
    {
        int n;
        cin >> n;
        string m;
        while(n--)
        {
            cin >> m;
            int cnt=0,min=0;
            int num[105]={0};
            for(int i=0 ; i<(int)m.length() ; i++)
            {
                num[i]=m[i]-'0';
                if(num[i]==0)
                {
                    cnt++;
                }
            }
            for(int i=0 ; i<(int)m.length()-1 ; i++)
            {
                for(int j=0 ; j<(int)m.length()-1-i ; j++)
                {
                    int t;
                    if(num[j] > num[j+1])
                    {
                        t = num[j];
                        num[j] = num[j+1];
                        num[j+1] = t;
                    }
                }
            }
           
            for(int i=m.length()-1 ; i>=0 ; i--)
            {
                cout << num[i];
            }
            cout << ' ';
            if(cnt==(int)m.length())
    
                    cout << min;
            else 
            {
                for(int i=0 ; i<=(int)m.length() ; i++)
                {
                 if(num[i]!=0)
                    cout << num[i];
                }
            }
            cout << '\n';
        }
        return 0;
    }
    
    • 0
      @ 2023-10-13 13:33:44
      //字符串大数模拟
      #include<stdio.h>
      #include<string.h>
      char ni[1000000];
      int main()
      {
          int n,b,c,m;
          scanf("%d",&n);
          int bi[10000]={0};
          while(n--) 
          {
              scanf("%s",ni);
              b=strlen(ni);
              for(c=0;c<b;c++) 
              {
                  ni[c]=ni[c]-'0';//将字符值转化成数字值
              }
              for(c=0;c<b;c++) 
              {
                  m=ni[c];
                  bi[m]++;//录入0~9数字出现次数
              }
              for(c=9/*从9开始输出*/;c>=0;c--) 
              {
                  while(bi[c]!=0) 
                  {
                      bi[c]--;
                      printf("%d",c);
                  }
              }
              printf(" ");
              for(c=0;c<b;c++) 
              {
                  m=ni[c];
                  bi[m]++;//重新录入
              }
                  bi[0]=0;
              for(c=1/*从1开始输出*/;c<=9;c++) 
              {
                  while(bi[c]!=0) 
                  {
                      bi[c]--;
                      printf("%d",c);
                  }
              }
              if(ni[0]==0&&b==1) 
                  printf("0");
              printf("\n");
          }
      }
      
      • 1

      信息

      ID
      203
      时间
      1000ms
      内存
      128MiB
      难度
      8
      标签
      (无)
      递交数
      1189
      已通过
      180
      上传者