2013 年 X 月 X 日,俄罗斯办理了斯诺登的护照,于是他混迹于一架开往委内瑞拉的飞机。但是,这件事情太不周密了,因为 FBI 的间谍早已获悉他的具体位置——但这不是最重要的——最重要的是如果要去委内瑞拉,那么就要经过古巴,而经过古巴的路在美国的掌控之中。
丧心病狂的奥巴马迫降斯诺登的飞机,搜查时却发现,斯诺登杳无踪迹。但是,在据说是斯诺登的座位上,发现了一张纸条。纸条由纯英文构成:Obama is a two five zero.
(以 .
结束输出,只有 66 个单词+一个句号,句子开头如没有大写亦为合法)这句话虽然有点无厘头,但是警官陈珺骛发现这是一条极其重要的线索。他在斯诺登截获的一台笔记本中找到了一个 C++ 程序,输入这条句子后立马给出了相对应的密码。陈珺鹜高兴得晕了过去,身为警官的你把字条和程序带上了飞机,准备飞往曼哈顿国际机场,但是在飞机上检查的时候发现——程序被粉碎了!飞机抵达华盛顿只剩 55 分钟,你必须在这 55 分钟内编写(杜撰)一个程序,免受上司的 10000000000 \bmod 1010000000000mod10 大板。破译密码的步骤如下:
(1)找出句子中所有用英文表示的数字 (\leq 20)(≤20),列举在下:
正规:one two three four five six seven eight nine ten eleven twelve
thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty
非正规:a both another first second third
。为避免造成歧义,another
算作 11 处理。
(2)将这些数字平方后对 100100 取模,如 00,05,11,19,86,9900,05,11,19,86,99。
(3)把这些两位数按数位排成一行,组成一个新数,如果开头为 00,就去 00。
(4)找出所有排列方法中最小的一个数,即为密码。
输入格式
一个含有 66 个单词的句子。
输出格式
一个整型变量(密码)。如果没有符合要求的数字出现,则输出 0
输入输出样例
输入 #1 输出 #1
Black Obama is two five zero . 425
解析:
本题重点是要如何将单词转化为数字,
以及要输出的是最小,故只需要将得到的数字排序即可。
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string s;
getline(cin,s);
vector<string>word;
vector<string>Wnum = {"one","another","a","another","first","both","second","two","third","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"};
vector<string>answer;
vector<int>num;
int key = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == ' ') {
string temp = s.substr(key, i -key);
key = i+1;
word.push_back(temp);
}
}
//string temp = s.substr(key, s.size() - key);
//word.push_back(temp);
for (int i = 0; i < word.size(); i++) {
for (int j = 0; j < Wnum.size(); j++) {
if (word[i] == Wnum[j]) {
if (j == 0 || j == 1 || j == 2 || j== 3|| j == 4) {
num.push_back(1);
}
else if (j == 5 || j == 6 ||j ==7) {
num.push_back(2);
}else if (j == 9 || j == 8) {
num.push_back(3);
}
else {
num.push_back(j - 6);
}
}
}
}
if (num.size() == 0) {
cout << "0";
return 0;
}
for (int i = 0; i < num.size(); i++) {
int t = num[i] * num[i];
t = t % 100;
num[i] = t;
}
sort(num.begin(), num.end());
for (int i = 0; i < num.size(); i++) {
if (num[i] < 10&&i != 0) {
cout<<"0";
}
cout << num[i];
}
return 0;
}