SHARE
TWEET

UVA - Phone List (vector)

jakaria_hossain May 8th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fastread() (ios_base::sync_with_stdio(false),cin.tie(NULL));
  4. int main()
  5. {
  6.     fastread()
  7.     int t;
  8.     cin>>t;
  9.     for(int j=1;j<=t;j++)
  10.     {
  11.         vector<string>phn;
  12.         int n;
  13.         cin>>n;
  14.         string s;
  15.         for(int i=0;i<n;i++)
  16.         {
  17.             cin>>s;
  18.             phn.push_back(s);
  19.         }
  20.         sort(phn.begin(),phn.end());
  21.         bool x=false;
  22.         for(int i=0;i<n-1;i++)
  23.         {
  24.             s= phn[i+1].substr(0,phn[i].size());
  25.             if(s==phn[i])
  26.             {
  27.                 x=true;
  28.                 break;
  29.             }
  30.         }
  31.         printf("Case %d: ",j);
  32.         if(x)printf("NO\n");
  33.         else printf("YES\n");
  34.     }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top