5 条题解

  • 2
    @ 2025-1-8 11:32:23
    #include <iostream>
    #include <algorithm>
    #include <string>
    using namespace std;
    
    int main()
    {
        int n;
        cin >> n;
        string a;
        while (n--)
        {
            cin >> a;
            sort(a.begin(), a.end());
            for (int i = 0; i < a.size(); i++)
            {
                cout << a[i]<<" ";
            }
            cout << endl;
        }
        return 0;
    }
    }strlen测量的是字符串常量,而cin就表明这个字符串不是常量是变量,所以我们用size()去测量长度,用的是c++里面的string类型定义字符串
    
    • @ 2025-6-28 9:03:10

      字符串的大小是固定的,3,不用size()

    • @ 2025-8-25 13:40:03

      @ 这个只是一个方法,你写3也行

  • 1
    @ 2025-9-27 23:46:58

    稍微取巧一点的办法

    #include <stdio.h> int main() { int n; scanf("%d",&n); getchar(); char l; for(int x=0;x<n;x++){ char a,b,c; scanf("%c%c%c",&a,&b,&c); if(a>b){ l=a; a=b; b=l; } if(a>c){ l=a; a=c; c=l; } if(b>c){ l=b; b=c; c=l; } printf("%c %c %c\n",a,b,c); getchar(); } return 0; }

    • 1
      @ 2023-7-28 2:26:51

      可以理解一下sort函数用法

      #include<iostream>
      #include<algorithm>
      using namespace std;
      int main() {
      	int n;
      	cin >> n;
      	while (n--) {
      		string temp;
      		cin >> temp;
      		sort(temp.begin(), temp.end());
      		cout << temp[0]<<" "<<temp[1]<<" "<<temp[2]<<endl;
      	}
      }
      
      • 0
        @ 2025-10-12 8:48:22

        #include<stdio.h> #include<string.h>

        int main()

        {

        int n;

        scanf("%d",&n);

        while(n--) { char str[100]; scanf("%s",str); int len=strlen(str);

        char *p; char *p1;

        for(int i=0;i<len-1;i++) {

        for(int j=0;j<len-1-i;j++) { p=&str[j]; p1=&str[j+1]; char tem; if(*p>*p1) { tem=*p1; *p1=*p; *p=tem; } } } for(int i=0;i<len;i++) { printf("%c ",str[i]); } printf("\n"); } return 0; }

        • 0
          @ 2024-12-13 10:38:59
          #include<stdio.h>
          #include<string.h>
          //#include <algorithm.h> 
          //#include<stdlib.h>
          int main(void)
          {
              int n;
              scanf("%d",&n);
              getchar();
              while(n--){
                  char arr[1010];
                  gets(arr);
                  int  len =strlen(arr);
                  //sort(arr,arr+len);
                  for(int i=1;i<len;i++){
                      for(int j=0;j<len-i;j++){
                          if(arr[j]>arr[j+1]){
                              int t =arr[j];arr[j]=arr[j+1];arr[j+1]=t;
                          }
                      }
                  }
                  for(int i=0;arr[i]!='\0';i++){
                      if(i!=0)printf(" ");
                      putchar(arr[i]);
                  }printf("\n");
              }
              return 0;
          }
          
          
          • @ 2024-12-13 10:39:28

            我用的是c语言

        • 1

        信息

        ID
        120
        时间
        3000ms
        内存
        128MiB
        难度
        7
        标签
        递交数
        2510
        已通过
        575
        上传者