Title DescriptionDescription General text Editor has the ability to find words, which can quickly locate the position of a particular word in the article, and some can also count the number of occurrences of a particular word in the article.
Now, you are programmed to implement this function, the specific requirement is: Given a word, please output it in the given article the number of occurrences and the first occurrence of the position. Note: When matching words, the case is not case sensitive, but the exact match is required, i.e. the given word must be associated with the article
One of the independent words in is exactly the same case-insensitive (see Example 1), if the given word is only part of a word in the story (see Sample 2).
input/output format input/output
Input Format:
The input file name is stat.in, 2 lines.
The 1th act is a string that contains only letters that represent a given word;
The 2nd behavior is a string that may contain only letters and spaces that represent a given article.
output Format:
The output file name is Stat.out.
Only one row, if you find a given word in the article output two integers, two integers separated by a space, respectively, the number of occurrences of the word in the article and the first occurrence of the position (that is, in the first occurrence of the article, the position of the first letter in the article, position from 0); If the word doesn't appear in the article, An integer-1 is output directly.
input and Output sample sample Input/output
sample Test point # #
Input Sample:
"Input Sample 1"
To
To being or not to being is a question
"Input Sample 2"
To
Did the Ottoman Empire lose it power at that time
Sample output:
"Output Example 1"
2 0
"Output Example 2"
-1
DescriptionDescription Data range
1≤ word length ≤10.
1≤ article length ≤1,000,000.
noip2011 popularization Group 2nd idea: Loop to the end, encounter spaces, determine whether the words before the space match to find the word, is the word output position, otherwise not found, output-1. The code is as follows (this code comes from my teacher: http://www.cnblogs.com/huashanqingzhu/p/4051137.html):
1#include <stdio.h>2#include <string.h>3 intMain ()4 { 5 Chars1[ -],s2[ +]; 6 intF1; 7 Longfirst=-1, num=0;//First: The subscript that appears for the initial time. Num: Total number of occurrences8 Charch; 9 inti; Ten intindex=-1;//indicates the subscript for the current scanned article Onescanf"%s", S1); AGetChar ();//absorbing carriage return characters - for(i=0; s1[i]!=' /'; i++) - { the if(s1[i]>='A'&&s1[i]<='Z')//if uppercase, it becomes a lowercase letter -s1[i]=s1[i]+ +; - } -f1=0;//You have not started to enter new words in the article +I=0;//The characters of the Word entered from the article in the S2 array - while((Ch=getchar ())!=eof)//not until the end . + { Aindex++; at if(ch==' ')//Space - { - if(f1==0) - { - Continue;//Jump out of the loop - } in Else - { tos2[i]=' /';//to the end of the table here + if(strcmp (s1,s2) = =0)//if two is as big as a - { the if(first==-1) *first=index-strlen (S2); $num++;//appeared, num++.Panax Notoginseng } -I=0; thef1=0; + } A } the Else + { -f1=1; $ if(ch>='A'&&ch<='Z') ch=ch+ +; $s2[i]=ch; -i++; - } the } - if(num>0)//have appearedWuyiprintf"%d%d\n", Num,first); the Elseprintf"-1\n");//never showed up. - return 0; Wu}
Noip2011-Universal Group Rematch-second question-count words