求助大佬,本地测试无误,提交答案时RE
查看原帖
求助大佬,本地测试无误,提交答案时RE
672906
My0sot1s楼主2022/2/11 17:09
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

char article[1000001];
int main(){
	int count=0,pos=0,zz=0;
	char word[11];
	char c;
	bool flag=false;
	cin >> word;
	for(int i=0;i<strlen(word);i++){
		if(word[i]<='Z')word[i]+=32;
	}
	getchar();
	while((c=getchar())!='\n'){
		if(c!=' '){
			if(c<='Z')c+=32;
			article[zz++]=c;
		}else{
			zz=0;
			if(!strcmp(word,article)){
				count++;
				if(!flag){
					flag=true;
				}
			}else{
				if(!flag)pos=pos+strlen(article)+1;
			}
			memset(article,0,sizeof(article));
		}
	}
	if(flag){
		cout << count << ' ' << pos;
	}else{
		cout << -1;
	}
	return 0;
}

应该是12行、16行的cin和getchar的问题,求大佬解释下原理

2022/2/11 17:09
加载中...