http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1875
#include <vector> #include <iostream> #include<algorithm> #include <string> #include <cstring> using namespace std; int main(){ vector<string> phonelist; int testcast; cin >> testcast; while(testcast--){ phonelist.clear(); int n; cin >> n; string str; for(int i = 0; i < n; i++){ cin >> str; phonelist.push_back(str); } sort(phonelist.begin(), phonelist.end()); // for(int i = 0; i < n; i++){ // cout << phonelist[i] << endl; // } int flag = 0; for(int i = 0; i < n - 1; i++){ if(strcmp(phonelist[i+1].substr(0, phonelist[i].length()).c_str(), phonelist[i].c_str()) == 0){ flag = 1; break; } } if(flag == 0){ cout << "YES" << endl; }else{ cout << "NO" << endl; } } }