Your first call to getline, will be consuming the <CR> character at the end of your number, so your string variable will be an empty string. You should call
getline
to clear the input. You also should not use that
for
loop top get the length of the input string, since you can either get it by
s.length()
, or use an iterator on the string. The simplest way to get your code working would be to modify the beginning as follows:
string s;
while(cin>>n)
{
getline(cin,s); for(int j = 1; j <= n; j++)
{
getline(cin, s);
int count = 0;
int len=s.length();
...