记录编号 141941 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [国家集训队2011]悄悄话 最终得分 100
用户昵称 Gravatarcstdio 是否通过 通过
代码语言 C++ 运行时间 0.060 s
提交时间 2014-12-05 10:39:28 内存使用 0.35 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
const int WORD_NUM=20,SIZEL=10010;
string dict_lis[WORD_NUM]={"you","it","he","do","they","we","i","and"
,"but","how","was","is","are","the","on","in","of","to","all","a"};
set<string> dict;
int c_val[26]={0};
bool lowercase(char c){
	return 'a'<=c&&c<='z';
}
void prepare(void){
	for(int i=0;i<WORD_NUM;i++) dict.insert(dict_lis[i]);
	char t1[]={'e','t','a','o','i','n','s','r'};//常见字
	char t2[]={'z','q','j','x','k','v','b','p'};//不常见字
	for(int i=0;i<8;i++) c_val[t1[i]-'a']++,c_val[t2[i]-'a']--;
}
int calc(string &s,int type[]){
	int ans=0;
	for(int i=0;i<s.size();i++){
		if(lowercase(s[i])) ans+=c_val[s[i]-'a'];//统计字母权值
		if(s[i]=='i'&&type[i]==1){
			ans+=5;//特判单词"I"
			if(i+1<s.size()&&s[i+1]=='\'') ans+=3;//特判"I'",因为这是唯一的"单字+'"
		}
		if(s[i]=='\'')//特判:"'s"和"'m"
			if(i+1<s.size()&&(s[i+1]=='m'||s[i+1]=='s')) ans+=4;
	}
	int i=0,j;
	while(i<s.size()){
		while(i<s.size()&&!lowercase(s[i])) i++;
		string t="\0";
		j=i;
		while(j<s.size()&&lowercase(s[j])) t+=s[j++];
		if(dict.count(t)) ans+=4;//出现单词
		i=j;
	}
	return ans;
}
int type[SIZEL]={0};//小写0大写1其余2
string text[26];
void turn_mark(string &s){//转小写并且在type中标记类型
	for(int i=0;i<s.size();i++){
		if('A'<=s[i]&&s[i]<='Z'){
			s[i]+='a'-'A';
			type[i]=1;
		}
		else if(!lowercase(s[i])) type[i]=2;
	}
}
void crypt(string &a,string &b,int k){//试图以偏移量k解密
	b="\0";
	for(int i=0;i<a.size();i++){
		if(lowercase(a[i])) b+=char('a'+(a[i]-'a'+k)%26);
		else b+=a[i];
	}
}
void print(string &s){
	for(int i=0;i<s.size();i++)
		if(type[i]==1) s[i]+='A'-'a';
	cout<<s<<endl;
}
void work(void){
	int mx=0,id=0;
	memset(type,0,sizeof(type));
	getline(cin,text[0]);
	turn_mark(text[0]);
	for(int i=1;i<26;i++) crypt(text[0],text[i],i);//尝试不同的解密姿势
	for(int i=0;i<26;i++){
		int now=calc(text[i],type);
		if(now>mx){
			mx=now;
			id=i;
		}
	}
	print(text[id]);
}
int main(){
	freopen("msg.in","r",stdin);
	freopen("msg.out","w",stdout);
	prepare();
	int T=10;
	while(T--) work();
	return 0;
}