noip2023t1求调
  • 板块学术版
  • 楼主liverxiwo
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/11/23 13:58
  • 上次更新2023/11/23 18:06:47
查看原帖
noip2023t1求调
1162380
liverxiwo楼主2023/11/23 13:58
#include <bits/stdc++.h>
using namespace std;
bool compare(string a, string b) {
    int len = min(a.length(), b.length());
    for (int i = 0; i < len; i++) {
        if (a[i] != b[i]) {
            return a[i] < b[i];
        }
    }
    return a.length() < b.length();
}
int main() {
    int n, m;
    cin >> n >> m;
    vector<string> words(n);
    for (int i = 0; i < n; i++) {
        cin >> words[i];
    }
    sort(words.begin(), words.end(), compare);
    for (int i = 0; i < n; i++) {
        bool satisfiesCondition = true;
        for (int j = 0; j < n; j++) {
            if (i != j && words[i] == words[j]) {
                satisfiesCondition = false;
                break;
            }
            for (int k = 0; k < m; k++) {
                if (words[i][k] < words[j][k]) {
                    satisfiesCondition = false;
                    break;
                }
            }
            if (!satisfiesCondition) {
                break;
            }
        }
        if(n=1){
        	cout<<"1";
        	return 0;
		}
        if (satisfiesCondition) {
            cout << "0";
        } else {
            cout << "1";
        }
    }
    cout << endl;
    return 0;
}

此代码过第一个点(也是唯一一个特判过的,也能过样例,但是其他就没办法了,求调)

2023/11/23 13:58
加载中...