社区讨论

RE且WA求条

B4069[GESP202412 四级] 字符排序参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@mhj9atpx
此快照首次捕获于
2025/11/03 22:49
4 个月前
此快照最后确认于
2025/11/03 22:49
4 个月前
查看原帖
CPP
#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin >> t;
    while (t --){
        string s[100];
        int n;
        cin>>n;
        for (int i = 0; i < n; i ++)
            cin >> s[i];
        for (int i = 0; i < n; i ++){
            for (int j = 0; j < n ; j ++){
                if (s[i] > s[i + 1]){
                    swap (s[j], s[j + 1]);
                }
            }
        }
        string st = "";
        for (int i = 0; i < n - 1; i ++){
            st += s[i];
        }
        bool flag = 0;
        int l=st.size()*n-1;
        for(int i=0;i<l-1;i++){
            if (st[i] > st[i + 1]){
                flag = 1;
                break;
             //   printf("o=%d i=%d st[i]=%d (>) st[i+1]=%d \n",o,i,st[i],st[i+1]); 测试
            }
         //   printf("i=%d l=%d l*n-1=%d o=%d i=%d st[i]=%c (<) st[i+1]=%c\n",i,l,o,i,st[i],st[i+1]); 测试too
        }
        if (flag) printf("0\n");
        else printf("1\n");
    }
    return 0;
}

回复

2 条回复,欢迎继续交流。

正在加载回复...