【安徽省选2003】短文评估

                                               短文评估

题目描述

为了维持生计,上学期期末迎考期间小可可在育红小学兼任了英语助教。首要任务就是协助英语教研室的老师们挑选合适的短文作为寒假作业布置给小朋友们,以提高他们的英语阅读能力。

挑选短文有一个评价标准。那就是同样长的文章,出现的单词越少越好,也就是说文章中词汇出现的频度越高越好。小可可根据思路设计了一个评估函数:

      

这个函数值越大,文章阅读难度越小。其中:T 是待评估的短文;Q(T)是短文中的单词数量,相同的单词重复计算;ψ(T)是短文 T 中单词构成的集合,单词是不区分大小写的,且该集合中没有重复的元素;f(w,T) 表示单词 w 在短文 T 中出现的次数。表示短文 T 中出现的各个不同单词的出现次数的四次方和。

为了简化处理,同一个英语单词的不同形态(如复数、过去式、过去分词等)算作不同单词。除了英文字母,短文中出现的数字和标点符号都不算单词,只能算作分隔符。例如短文:The International Olympic Committee (IOC) will decide the 2012 Olympic Games host in three years at a meeting in Singapore. 
这篇短文的 =19。 是由 The,International,Olympic,Committee,IOC,will,decide,Games,host,in,three,years,at,a,meeting,Singapore等单词构成的集合(注意:The 和 the算同一个单词),这些单词在该短文中出现的次数分别是 2,1,2,1,1,1,1,1,1,2,1,1,1,1,1,1。

因此:

      

所以该短文的评估值

      

计算短文的评估值可不是一件轻松的事情,为了提高小可可的工作效率,请你帮她编写一个程序,只需要求出计算短文评估值所需要的 P(T) 和 Q(T) 。

输入格式

输入文件中所有的内容构成了待评估短文 T ,并且已知待评估短文的 Q(T)≤1000,任何一个单词的长度不超过 40 个字符,出现的次数不超过 50 。文章可能有很多段,段与段之间可能有一行空行,也可能没有。没有单词被拆分长两段。

输出格式

在一行输出两个整数,分别代表 P(T) 和 Q(T) 。两个整数之间用一个空格隔开。

样例数据 1

输入  [复制]

The International Olympic Committee (IOC) will decide the 2012 Olympic Games host in three years at a meeting in Singapore.

输出

61 19

样例数据 2

输入

The International Olympic Committee (IOC) will decide the 2012 Olympic Games host in three years at a meeting in Singa23pore.

输出

62 20

解析:

       请允许我称其为一道模拟题。

       做法有很多,可以用哈希或者 trie 树。注意一下细节就行了

代码(trie树)

#include <bits/stdc++.h>
using namespace std;

const int Max=10101;
int n,m,ans1,len,size,tot,maxx;
long long ans2;
int num[Max];
char ch[Max],s[Max];
struct shu{int son[30],num;};
shu tree[Max];

inline int get_int()
{
	int x=0,f=1;
	char c;
	for(c=getchar();(!isdigit(c))&&(c!='-');c=getchar());
	if(c=='-') {f=-1;c=getchar();}
	for(;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+c-'0';
	return x*f;
}

inline void build()
{
   int position = 0;
   for(int i=1;i<=size;i++)
   {
   	 if(!tree[position].son[s[i]-'a']) tree[position].son[s[i]-'a'] = ++tot;
   	 position = tree[position].son[s[i]-'a'];
   }
   tree[position].num ++;
}

inline long long calc(int num)
{
   return (long long)num*num*num*num;
}

inline void search()
{
   for(int i=1;i<=tot;i++)
     if(tree[i].num > 0) ans2+=calc(tree[i].num);
}

int main()
{
	while(scanf("%s ",ch+1)!=EOF)
	{
	  len=strlen(ch+1);
	  for(int i=1;i<=len;i++) if(ch[i] >='A' && ch[i] <= 'Z') ch[i] = 'a' + ch[i] - 'A';
	  for(int i=1;i<=len;i++)
	  {
	  	if(ch[i] >='a' && ch[i] <= 'z')
	  	{
	  	  ans1++,size=0;
	  	  while(1)
	  	  {
	  	  	if(ch[i] >='a' && ch[i] <= 'z') s[++size] = ch[i];
	  	  	else break;
	  	  	i++;
	  	  }
	  	  build();
	  	}
	  }
	}

	search();

	cout<<ans2<<" "<<ans1<<"\n";
	return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_38083668/article/details/81173738