This is my code here i am trying to find the biggest length of same length characters at a time like "a a a bb bb bc sa sa a a" so answer is 5 for two characters at a time for 5 times adjacently .
this is my code , my question is that when i am trying to take the input , for my first input it is not going to getline but printf in last lines and then it takes a line and prints output
like if i give 5 it writes 1 then it takes getline , but i want it to take getline first rather than printf, in this way for my 5 input it prints 1 and 4 desired outputs .i want 5 desired can you tell me why..
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int main()
{
    int a,j;
    scanf("%d",&a);
    for(j=0;j<a;j++)
    {
        vector<int> v;
        string s;
        getline(cin,s);
        int i,cnt =0;
        for(i=0;i<s.length();i++)
        {
            if(s[i] != ' ')
            {
                cnt++;
            }
            else
            { 
                v.push_back(cnt);
                cnt =0;
            }
        }
        v.push_back(cnt);
        int k=0;
        int ps =0;
        int sp=0;
        while(k<v.size()-1)
        {
            if (v[k+1] - v[k] == 0)
            {
                sp++;
                k++;
            }
            else
            if (sp >= ps)
            {
                ps = sp;
                 k++;
                sp=0;
            }
            else
            {
                k++;
                sp=0;
            }
        }
        if (sp<ps)
        printf("%d",ps+1);
        else
        printf("%d",sp+1);
    }
    return 0;
}    
 
     
     
    