P1603 斯诺登的密码

#include<bits/stdc++.h>
using namespace std;
map<string,int> mp;
string hashtable[21]={"zero","one","two","three","four","five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"};
void initi(){
	for(int i=0;i<=20;i++){
		mp[hashtable[i]]=i;
	}
	mp["a"]=1;mp["both"]=2;mp["another"]=3;
	mp["first"]=1;mp["second"]=2;mp["third"]=3;
}
bool cmp(string a,string b){
	return a<b;
}
int main()
{
	freopen("in.txt","r",stdin);
	vector<string> ppp;
	initi();
	for(int i=0;i<6;i++){
		string temp;cin>>temp;
		if(temp[temp.length()-1]=='.') temp=temp.substr(0,temp.length()-1);
		transform(temp.begin(),temp.end(),temp.begin(),::tolower);
		if((mp[temp]<=20&&mp[temp]>0)||temp=="zero"){
			int x=(mp[temp]*mp[temp])%100;
			string t=to_string(x);
			if(t.length()==1) t='0'+t;
			//cout<<t<<endl;
			ppp.push_back(t);
		}
	}
	sort(ppp.begin(),ppp.end(),cmp);
	string ans;
	for(int i=0;i<ppp.size();i++){
		ans+=ppp[i];
	}
	//cout<<ans<<endl;
	int cnt=0;
	for(int i=0;i<ans.length();i++){
		if(ans[i]=='0') cnt++;
		else break;
	}
	ans=ans.substr(cnt);
	if(ans.length()==0) cout<<0;
	else
	cout<<ans;
	return 0;
}

第三个测试点是0;

第二、五测试点是非常规数字;

第一、四测试点是常规数字;

猜你喜欢

转载自blog.csdn.net/csg3140100993/article/details/82713149