本题第一个考点就是利用string[ ]和int[ ]实现,字符串与数字转换
第二个考点就是贪心
排在前的越小越好
#include <bits/stdc++.h>
using namespace std;
string s[30]={"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"};
int num[30]={1,4,9,16,25,36,49,64,81,0,21,44,69,96,25,56,89,24,61,0,1,4,1,1,4,9};
int flag,st[10],cnt;
string a;
int main(int argc, char** argv) {
for(int l=0;l<6;l++){
cin>>a;
for(int i=0;i<26;i++){
if(a==s[i]) {
st[cnt++]=num[i];
break;
}
}
}
cin>>a;
sort(st,st+cnt);
for(int i=0;i<6;i++){
if(!flag){
printf("%d",st[i]);flag=1;
}else if(st[i]!=0){
printf("%02d",st[i]);
}
}
return 0;
} 
京公网安备 11010502036488号