题目:P1603
题意:
(1)找出句子中所有用英文表示的数字(≤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
(2)将这些数字平方后%100,如00,05,11,19,86,99。
(3)把这些两位数按数位排成一行,组成一个新数,如果开头为0,就去0。
(4)找出所有排列方法中最小的一个数,即为密码。
Ps.输入是一个含有6个单词的句子。
分析:
水题,字符串处理+模拟,不过要注意审题就是了。
想到了三种方法吧…
①用C的char数组和strcmp(s1,s2)函数,s1和s2相同返回0,不相同返回非零值。
②用C++的string类型和s1==s2,s1和s2相同为true,不相同为false。
③用STL的map映射,从string映射到int,这样m[“one”]=1,用数组下标的形式来直接访问会快些,也方便些。
使用 map.count ( key )函数,返回map中key元素的个数,在map里面非1即0,存在为1,不存在为0。
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
map<string,int> num;
num["zero"]=0;
num["one"]=1;
num["a"]=1;
num[