icpc:problems:luogup1603
problems | |
---|---|
名称 | 斯诺登的密码 |
题目编号 | P1603 |
题目链接 | luogu.com.cn/… |
来源 | Luogu |
算法分类 | 入门_字符串 |
难易程度 | 容易 |
斯诺登的密码
想法
认真读题,对于后续的一位数是不能省略0的。
代码实现
#include<iostream> #include<string> #include<algorithm> using namespace std; string mp[21]={ " ","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty" }; int turn(string temp) { for(int i=1; i<=20; i++) if(temp == mp[i]) return i; if(temp == "a" || temp == "another" || temp == "first") return 1; if(temp == "both" || temp == "second") return 2; if(temp == "third") return 3; return -1; } bool cmp(string a, string b){ return a.length() < b.length() || (a.length()==b.length() && a < b); } int main() { string str[10], line[10]; int cnt = 0; for(int i=1; i<=6; i++) { cin >> line[i]; int temp = turn(line[i]); if(temp == -1)continue; temp = temp * temp % 100; if(temp == 0)continue; line[cnt++] = to_string(temp); } sort(line, line+cnt, cmp); for(int i=0; i<cnt; i++){ if(line[i].length() == 1 && i != 0) cout << "0"; cout << line[i]; } if(cnt == 0) cout << "0"; return 0; }
/app/www/public/data/pages/icpc/problems/luogup1603.txt · 最后更改: 2024/03/13 15:42 由 温婕莺