WORDCNT

Spoj Problem Solution WORDCNT
#include<cstdio>
#include<iostream.h>
void sort(int a[],int b)
{
int temp;
for(int j=0;j<b-1;j++)
for(int i=j+1;i<b;i++)
if(a[j]>a[i])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}    
}

main()
{

int t;
cin>>t;
char a[100000];
while(t--)
{
int flag[1000]={0};

          int i=0;
         
      
      
      // while(temp=='\n')scanf("%c",&temp);  
scanf("%c",&a[i++]);while(a[i-1]<97){i=0;scanf("%c",&a[i++]);}  
if(a[0]!='\n'){      
          int lm=0,hh=1,rr=0;
          while(true)
          {
          if(a[i-1]>96)
          {
          lm++;   
        //cout<<lm<<endl;
          }
          else if(a[i-1]==32||a[i-1]=='\n')
          {
         if(hh==lm)
           {
           flag[rr]++;
           lm=0;
          // cout<<"iam flag "<<flag[rr]<<endl;
           }
           else if(a[i-2]!=32)
           {
           hh=lm;
           lm=0;
           rr++;
           flag[rr]=1;
          // cout<<hh<<" "<<rr<<" "<<flag[rr-1]<<endl;
           }
           if(a[i-1]=='\n')break;
                                 
          }
          scanf("%c",&a[i++]);
}     
      sort(flag,i);
     // for(int h=0;h<i;h++)
      //cout<<flag[h]<<" ";
      cout<<flag[i-1]<<endl;
      }
      }

}

No comments:

Post a Comment