题目连接:该题是luogu试炼场的2-5:T1
题目大意:
1 给n个单词,里面会有与数字相关的英文;
2 对于这些数字进行一系列的处理,最后输出特定值
解题思路:
1 主要是掌握字符串的存储
2 字符串与数字的转换
上代码
//luogu1603:斯诺登的密码
//考察字符串的应用
//1 单词的存储与转化
//2 排序与输出
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[10][20];
int ls=0,l,la=0,a[10];
char s1[30][20]={"0",
"one","two","three","four","five","six","seven",
"eight","nine","ten","eleven","twelve","thirteen","fourteen",
"fifteen","sixteen","seventeen","eighteen","nineteen","twenty"
};
char s2[10][20]={ "0","a","both","another"};
char s3[10][20]={ "0","first","second","third"};
int main()
{
while(scanf("%s",s[++ls])!=EOF) //读入的细节处理
{
l=strlen(s[ls]);
for(int i=0;i<l;i++)
{
if(s[ls][i]>='A'&&s[ls][i]<='Z') //过滤大写
s[ls][i]=s[ls][i]-'A'+'a';
}
}
for(int i=1;i<=ls;i++)//查出所有的数字
{
for(int j=1;j<=20;j++)//标准数字
{
if(strcmp(s[i],s1[j])==0) a[++la]=j;
}
for(int j=1;j<=3;j++)//非标数字 1
{
if(strcmp(s[i],s2[j])==0) a[++la]=j;
}
for(int j=1;j<=3;j++)//非标数字 2
{
if(strcmp(s[i],s3[j])==0) a[++la]=j;
}
}
for(int i=1;i<=la;i++)//字符转数字
{
a[i]*=a[i];
a[i]%=100;
}
sort(a+1,a+1+la);//排序求最小值
printf("%d",a[1]);
for(int i=2;i<=la;i++)
{
printf("%02d",a[i]);
}
return 0;
}