1 solutions
-
0
C++ :
#include<iostream> #include<string> #include<algorithm> using namespace std; bool cmp(string a,string b) { if(a.size()!=b.size()) return a.size()<b.size(); else return a<b; } int main() { int n; while(cin>>n,n) { string str[1005]; for(int i=0;i<n;i++) cin>>str[i]; sort(str,str+n,cmp); bool ok=true; for(int i=0;i<n-1;i++) for(int j=i+1;j<n;j++) if(str[j].find(str[i])==0) { ok=false;break; } ok?cout<<"YES\n":cout<<"NO\n"; } return 0; }
- 1
Information
- ID
- 20206
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By