24: Word Length, 24: Word Length
24: Word Length
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
Enter a word sequence. adjacent words are separated by one or more spaces. Calculate the length of each word accordingly.
Note: if there is a punctuation mark (such as a hyphen or comma), the punctuation marks are counted as part of the word that is connected to them. A string that is not separated by spaces is counted as a word.
-
Input
-
A word sequence contains at least one word and a maximum of 300 words. Each word is separated by at least one space. The total length of a word sequence cannot exceed 1000.
-
Output
-
Output the length of the corresponding word in sequence, separated by commas.
-
Sample Input
-
She was born in 1990-01-02 and from Beijing city.
-
Sample output
-
3,3,4,2,10,3,4,7,5
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 char a[10001]; 7 char b[10001]; 8 int main() 9 {10 int flag=0;11 gets(a);12 int l=strlen(a);13 int tot=0;14 for(int i=0;i<l;i++)15 {16 if(a[i]!=' ')tot++;17 18 else 19 {20 if(tot!=0)21 {22 cout<<tot<<",";23 }24 tot=0;25 }26 if(i==l-1)27 cout<<tot;28 29 }30 return 0;31 }