记录编号 324211 评测结果 AAAAAAAAAA
题目名称 [NOIP 2011]统计单词数 最终得分 100
用户昵称 GravatarRapiz 是否通过 通过
代码语言 C++ 运行时间 0.035 s
提交时间 2016-10-17 20:50:46 内存使用 6.27 MiB
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<cctype>
#define file(x) "stat."#x
const int LEN=1e6+10;
char a[LEN],b[LEN],buf[LEN];
int l1,l2,nxt[LEN],pos,cnt,tol,ans;
bool match(){
	if(l1!=l2) return false;
	for(int i=1;i<=l2;i++) if(a[i]!=tolower(b[i])) return false;
	return true;
}
bool read(){
	l2=0;
	pos++;
	while(buf[pos]&&isspace(buf[pos])) pos++;
	b[++l2]=buf[pos];
	while(isgraph(buf[pos+1])) b[++l2]=buf[++pos];
	return pos<=tol;
}
int main(){
	freopen(file(in),"r",stdin);
	freopen(file(out),"w",stdout);
	gets(a+1);
	gets(buf+1);
	l1=strlen(a+1);
	tol=strlen(buf+1);
	for(int i=1;i<=l1;i++) a[i]=tolower(a[i]);
	while(read()) {
		if(match()){
			if(!cnt) ans=pos-l2;
			cnt++;
		}
	}
	if(cnt) printf("%d %d",cnt,ans);
	else printf("-1");
}