5 条题解

  • 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;

    }

    • 1
      @ 2026-5-13 23:15:04
      /*
      因为回文串正序反序都一样,所以用字符串模拟数字,一个赋值为正序,一个为反序,再比较异同就可以了
      */
      

      C++C++ 1717

      //2026 5 14 17:47
      #include <iostream>
      #include <algorithm>
      #include <iomanip>
      #include <cstdio>
      #include <string>
      #include <ios>
      
      #pragma GCC optimize("Ofast")
      
      #define by
      #define code
      #define AC 0
      #define 一只傻兔
      
      using std::ios;
      using std::cin;
      using std::cout;
      using std::sort;
      using std::string;
      using std::freopen;
      
      code by 一只傻兔
      string 一只傻兔の代码 = {"C++17"};
      
      short N;
      string Number;
      
      bool Compare(int a, int b) {
      	return a > b;
      }
      
      signed main(void) {
      	//freopen("AC.in", "r", stdin);
      	//freopen("AC.out", "w", stdout);
      	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
      	cin >> N;
      	while(N--) {
      		cin >> Number;
      		sort(Number.begin(), Number.end(), Compare);
      		cout << Number << ' ';
      		sort(Number.begin(), Number.end());
      		while(Number[0] == '0' && Number.size() > 1) {
      			Number.erase(Number.begin());
      		}
      		cout << Number << '\n';
      	}
      	return AC;
      }
      

      ☞题目传送门☜

      ☞提交☜

      • 1
        @ 2025-11-28 21:58:09
        #include <iostream>
        #include <algorithm>
        using namespace std;
        #define int long long
        signed main() {
        	int t;
        	cin >> t;
        	while (t--) {
        		string a;
        		cin >> a;
        		int len = a.length();
        		int ss[105] = {0};
        		for (int i = 0 ; i < len ; i++) {
        			ss[i] = a[i] - '0';
        		}
        		if(ss[0]==0){
        			cout << 0 << " " << 0 << '\n';
        			continue;
        		}
        		sort(ss, ss + len);
        		for (int i = len - 1 ; i >= 0 ; i--) {
        			cout << ss[i] ;
        		}
        		cout << " ";
        		for (int i = 0 ; i <= len ; i++) {
        			if (ss[i] == 0) {
        				continue;
        			}
        			cout << ss[i];
        		}
        		cout << '\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
            标签
            (无)
            递交数
            1435
            已通过
            221
            上传者