3 条题解

  • 2
    @ 2025-10-6 15:19:41

    #include<stdio.h>

    #include<string.h>

    int main(){

    int n,m;

    char a[105];

    scanf("%d",&n);

    while(n--){

    int b[10]={0};记录每个数出现的次数

    int x=0;

    scanf("%s",a);

    m=strlen(a);

    for(int i=0;i<m;i++){//判断输入的值是否为0

    x=x+a[i]-'0';

    }

    if(x==0){

    printf("0 0\n");

    continue;

    }

    for(int i=0;i<m;i++){

    b[a[i]-'0']++;

    }

    for(int i=9;i>=0;i--){//从9开始输出,输出最大值

    while(b[i]>0){

    printf("%d",i);

    b[i]--;}

    }

    printf(" ");

    for(int i=0;i<m;i++){

    b[a[i]-'0']++;

    }

    for(int i=1;i<=9;i++){//从1开始输出最小值,不从0开始,0放前面无意义

    while(b[i]>0){

    printf("%d",i);

    b[i]--;}

    }

    printf("\n");

    }

    return 0;

    }

    • 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
        标签
        (无)
        递交数
        1321
        已通过
        195
        上传者