ccbeginner

UVa Q11362

Dec 11th, 2019
112
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string s[10000];
  5.  
  6. int32_t main(){
  7.     int t;
  8.     cin >> t;
  9.     while(t--){
  10.         int n;
  11.         cin >> n;
  12.         for(int i = 0; i < n; ++i)cin >> s[i];
  13.         sort(s, s+n);
  14.         bool yes = 1;
  15.         for(int i = 1; i < n && yes; ++i){//s[i], s[i-1]
  16.             if(s[i].size() < s[i-1].size())continue;
  17.             bool no = 1;
  18.             for(unsigned j = 0; j < s[i-1].size() && no; ++j){
  19.                 if(s[i-1][j] != s[i][j])no = 0;
  20.             }
  21.             if(no)yes = 0;
  22.         }
  23.         if(yes)cout << "YES\n";
  24.         else cout << "NO\n";
  25.     }
  26.     return 0;
  27. }
RAW Paste Data