记录编号 34291 评测结果 AAAAAAAAAA
题目名称 [NOIP 2011]统计单词数 最终得分 100
用户昵称 GravatarTruth.Cirno 是否通过 通过
代码语言 C++ 运行时间 0.366 s
提交时间 2011-12-07 22:04:40 内存使用 4.08 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;

char pass[4000000];

int main(void)
{
	freopen("stat.in","r",stdin);
	freopen("stat.out","w",stdout);
	int i,j,lw,lp,total=0,first=-1;
	char word[40]={0};
	bool found;
	cin.getline(word,39);
	cin.getline(pass,3999999);
	  lw=strlen(word);
	lp=strlen(pass);
	for (i=0;i<lw;i++)
		if (word[i]>='A'&&word[i]<='Z')
			word[i]=word[i]-'A'+'a';
	for (i=0;i<lp;i++)
		if (pass[i]>='A'&&pass[i]<='Z')
			pass[i]=pass[i]-'A'+'a';
	for (i=0;i<=lp-lw;i++)
	{
		found=true;
		for (j=0;j<lw;j++)
		{
			if (word[j]!=pass[i+j])
			{
				found=false;
				break;
			}
		}
		if (found)
			if (pass[i+lw]>='a'&&pass[i+lw]<='z')
				found=false;
		if (found)
			if (i-1>=0)
				if (pass[i-1]>='a'&&pass[i-1]<='z')
					found=false;
		if (found)
		{
			total++;
			if (first==-1)
				first=i;
		}
	}
	if (total==0)
		printf("-1\n");
	else
		printf("%d %d\n",total,first);
	return(0);
}