3 条题解

  • 1
    @ 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()

  • 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
      @ 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
    标签
    递交数
    2316
    已通过
    530
    上传者