https://www.luogu.org/problem/P1603
#include<bits/stdc++.h> using namespace std; struct s { string n; string t; } pass[26]= { {"one","01"},{"two","04"},{"three","09"},{"four","16"},{"five","25"},{"six","36"},{"seven","49"},{"eight","64"},{"nine","81"}, {"ten","00"},{"eleven","21"},{"twelve","44"},{"thirteen","69"},{"fourteen","96"},{"fifteen","25"},{"sixteen","56"},{"seventeen","89"}, {"eighteen","24"},{"nineteen","61"},{"twenty","00"},{"a","01"},{"both","04"},{"another","01"},{"first","01"},{"second","04"},{"third","09"} }; string searchs( string s) { for(int i=0; i<26; i++) { if(s==pass[i].n) { return pass[i].t;//在列表中查找是否存在,不存在返回00 } } return "00"; } int main() { bool output=false; //专为第三点设置 string str; string x[6]; for(int i=0; i<6; i++) { cin>>str; x[i]=searchs(str); } sort(x,x+6);//利用string字典序的特性即可升序排序 bool flag=false;//判断从哪里要开始输出0,什么时候不要输出0 for(int i=0; i<6; i++) { if(x[i]=="00") continue; if(x[i][0]=='0'&&flag==false) { //在最小数字判断第一位是否为0,如果是0,就直接输出第二位 flag=true; //标记 在以后遇到的数字都直接输出 } else cout<<x[i][0]; cout<<x[i][1]; output=true; } if(!output)cout<<"0";//整个过程中都没有输出最后补一个0 }