#5#7#8#9WA
#5自己测试输不了全部数据,不过看了下WA的提示和本地错的好像不一样
代码如下
#include <stdio.h>
#include <string.h>
int main(){
char word[11], sentence[1000010];
int count=0, wCount=0, pos=-1, posT=-1, judgingFlag=0;
int i=0, j=0;
gets(word);
while(word[i]!='\0'&&word[i]!='\r'&&word[i]!='\n'){
if(word[i]>='a' && word[i]<='z')
word[i] -= 32;
i++;
}
i=0;
gets(sentence);
do{
if(sentence[i-1]==' ' || judgingFlag==1 || i==0){
if(sentence[i]>='a' && sentence[i]<='z')
sentence[i] -= 32;
if(sentence[i] == word[wCount]&&sentence[i]!='\0'&&sentence[i]!='\r'&&sentence[i]!='\n'){
if(posT == -1){
posT = i;
}
judgingFlag = 1;
wCount++;
}
else{
if(wCount == strlen(word)){
count++;
if(pos == -1){
pos = posT;
}
}
judgingFlag = 0;
wCount = 0;
posT = -1;
}
}
i++;
//printf("%d %d\n", wCount, posT);
}while(sentence[i-1]!='\0'&&sentence[i-1]!='\r'&&sentence[i-1]!='\n');
if(count){
printf("%d %d", count, pos);
}
else{
printf("-1");
}
return 0;
}