Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 259 Accepted Runs: 126
This task is very simply, give you an article, you should just output how many words there are.
The words may be split by any separator such as ',' and '.' and so on.
The words only contains letters or digit and its length is at least one.
Input
Only one case, may have a lot of lines.
Output
Output the number of words.
Sample Input
Give you two strings, which are combined by two kinds of char 'x' and 'y'. In this task, the first string is always longer than the second string. If the first string's length is L, and the second string's length is M, you can easily know that there will be L-M+1 substrings of the first string, whose length is the same as the second string. In these substrings, you can change some 'x' to 'y' or 'y' to 'x', in order to make this string the same as the second string. And of course, different string may need to change different number of chars to achieve this target. Here, tmeteorj wants to know how many substring, which has the same size as the second string, can be changed to be the same as second string exactly by change K chars. Since tmeteorj is a very boring man, he wants to ask you Q times of such boring question. Of course you are not such boring, so you decide to write a program to answer those questions. Input In the first two lines, there will be two string. Followed by a positive integer q, means tmeteorj has q questions. There will be q positive integer, indicating the exactly change times in this question. The program should be process to EOF. Be careful, the length of the string will no longer than 100000, and the number of questions will no bigger than 10000. Output For each question, you should just output one line, indicates the number of different ways to make the second string be the substring of the first string. To make problem simple, you can only change the first string. Sample Input xxxxxyxxxxxxxx yy 2 1 2 yyyyy x 3 1 2 3 Sample Output 2 11 5 0 0
Sample Output
304
Source: TJU Team Selection 2014 Round1
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cctype>
using namespace std;
char str[50007];
int main ( )
{
int cnt = 0;
while ( ~scanf ( "%s" ,str ) )
{
int i = 0;
while ( str[i] )
{
if ( isalnum ( str[i] ) )
{
i++, cnt++;
while ( isalnum ( str[i] ) ) i++;
}
if ( str[i] ) i++;
}
}
printf ( "%d\n" , cnt );
}