Advertisement
Saleh127

UVA 11362

Jul 19th, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  5. string a[100005];
  6. bool cmp(string a,string b)
  7. {
  8. if(a.size()<b.size()) return 1;
  9. else if(a.size()==b.size())
  10. {
  11. if(a<b) return 1;
  12. else return 0;
  13. }
  14. return 0;
  15. }
  16. int main()
  17. {
  18. ios_base::sync_with_stdio(0);
  19. cin.tie(0);
  20. cout.tie(0);
  21.  
  22. test
  23. {
  24.  
  25. ll n,m,i,j,k,l=0;
  26.  
  27. cin>>n;
  28.  
  29. for(i=0; i<n; i++)
  30. {
  31. cin>>a[i];
  32. }
  33.  
  34. sort(a,a+n,cmp);
  35.  
  36. for(i=0; i<n; i++)
  37. {
  38. for(j=i+1; j<n; j++)
  39. {
  40. m=0;
  41.  
  42. for(k=0; k<min(a[i].size(),a[j].size()); k++)
  43. {
  44. if(a[i][k]!=a[j][k])
  45. {
  46. m=1;
  47. break;
  48. }
  49. }
  50.  
  51.  
  52. if(m==0)
  53. {
  54. l=1;
  55. break;
  56. }
  57. }
  58. if(l) break;
  59. }
  60.  
  61. if(l) cout<<"NO"<<endl;
  62. else cout<<"YES"<<endl;
  63.  
  64. }
  65.  
  66.  
  67. return 0;
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement