Advertisement
sabertooth09

Untitled

May 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int q;
  7.     cin>>q;
  8.     while(q--)
  9.     {
  10.         int n,i,h=0,t=0,temp=0,k=0;
  11.         scanf("%d",&n);
  12.         getchar();
  13.         char a[n];
  14.         gets(a);
  15.         for(i=0; i<n; i++)
  16.         {
  17.             if(a[i]=='H')
  18.             {
  19.                 h++;
  20.                 for(int j=i+1; j<n; j++)
  21.                 {
  22.                     if(a[j]=='H'||a[j]=='T')
  23.                     {
  24.                         temp=j;
  25.                         break;
  26.                     }
  27.                 }
  28.                 if(a[temp]=='H')
  29.                 {
  30.                     k=1;
  31.                     goto u;
  32.                 }
  33.                 else
  34.                 {
  35.                     t++;
  36.                     i=temp;
  37.                 }
  38.             }
  39.             else if(a[i]=='T')
  40.             {
  41.                 t++;
  42.                 for(int j=i+1; j<n; j++)
  43.                 {
  44.                     if(a[j]=='H'||a[j]=='T')
  45.                     {
  46.                         temp=j;
  47.                         break;
  48.                     }
  49.                     if(a[temp]=='T')
  50.                     {
  51.                         k=1;
  52.                         goto u;
  53.                     }
  54.                     else
  55.                     {
  56.                         h++;
  57.                         i=temp;
  58.                     }
  59.                 }
  60.             }
  61.         }
  62. u:
  63.         cout<<h<<" "<<t<<" "<<endl;
  64.         if(t!=h|| k==1)
  65.         {
  66.             cout<<"Invalid"<<endl;
  67.         }
  68.         else
  69.         {
  70.             cout<<"Valid"<<endl;
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement