社区讨论

字符串排序怎么卡过了

P9868[NOIP2023] 词典参与者 5已保存回复 12

讨论操作

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

当前回复
12 条
当前快照
1 份
快照标识符
@mifmet2p
此快照首次捕获于
2025/11/26 14:25
3 个月前
此快照最后确认于
2025/11/26 15:52
3 个月前
查看原帖
CPP
#include <bits/stdc++.h>
using namespace std;
string sp[3010];
string sq[3010];
bool cmp(char const& x, char const& y) {
    return x > y;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    if (n == 1) {
        cout << "1\n";
        return 0;
    }
    string s, ts;
    for (int i = 1; i <= n; i++) {
        cin >> s;
        ts = s;
        sort(ts.begin(), ts.end());
        sp[i] = ts;
        sort(s.begin(), s.end(), cmp);
        sq[i] = s;
    }
    for (int i = 1; i <= n; i++) {
        int j = 1;
        while (j <= n) {
            if (j == i or sp[i] < sq[j]) j++;
            else break;
        }
        if (j == n + 1) cout << 1;
        else cout << 0;
    }
    return 0;
}

回复

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

正在加载回复...