WORDCNT - Word Counting

no tags 

Nguyen is writing a small software for counting words in a string. He becomes bored after finishing the software very fast. He now wants to find the number of words P in the longest consecutive sequence of words of the same length.

Given a string containing only characters a...z and spaces (ASCII code is 32), a word is defined to be the longest sequence of non-space characters. Your task is to write a program to help Nguyen find the number P.


The input file consists of several data sets. The first line of the input file contains the number of data sets which is a positive integer and is not bigger than 20. The following lines describe the data sets.

For each data test, there is one single line containing the string to count words. There are less than 1000 words in the string. The length of each word does not exceed 20 characters.


For each data test, write in one line the number P Nguyen wants to find.


Sample Input
a aa bb cc def ghi
a a a a a bb bb bb bb c c	

Sample Output

hide comments
s_jindal00: 2017-06-13 10:41:16

can be solved without iss string stream! Just take care of the case when input is just an empty line. In that case run an infinite loop which will not break until an input line is given which has atleast 1 lowercase letter. Then process it output the answer and continue with next test case and do the same for that as well.

Last edit: 2017-06-13 10:41:29
cake_is_a_lie: 2017-02-24 06:04:28

easy in c++; just use stream I/O (getline and istringstream)

vengatesh15: 2017-01-28 11:21:50

consider \r and \t as delimiter that cost me 1 WA

sushantoberoi3: 2016-10-29 12:29:46

question is very easy but to take input in c++.....it took me 1/2 hour finally did it AC :)

Last edit: 2016-10-29 12:29:57
dwij28: 2015-12-30 07:44:04

Its relatively difficult to solve this question in c++ than in python not because the question is too good or time is too strict but because the input is very and i say VERY messed up .. Better use python ..

ganpya: 2015-08-07 08:52:38

try python ;). AC in one go

SangKuan: 2015-07-02 12:35:16

there will be more than one space bettwen of two words.and not need use "(str[index]<'a' || str[index]>'z')",
init a ascii vector,then from 'a' to 'z' is true, other is false.

:.Mohib.:: 2015-05-26 06:24:53

Have to do in python....finally ac...after lot of wa bcz of I/p format.... :)

Itachi: 2015-05-11 20:08:38

One of the problems where I/O gets into your nerves. Fun problem nonetheless.

i_am_looser: 2015-05-11 09:44:12

Really get ready to see lots of wa ...... finally ac after lots of wa's

Added by:Duc
Time limit:0.660s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:ACM Regional, Ho Chi Minh City 2008