P1603斯诺登的密码

题目https://www.luogu.org/problemnew/show/P1603

本题因为只需要输入六个单词所以变得简单
**

思路

**
1.用string 定义二维数组存储1-20的字符串 在特殊判断非常规数 并且存储到一个Int数组内(方+%100)
2.取模的时候注意如果是一为 会变为例如 01 02 03 04·········但是存到数组内只能为一位(这里思考一下如果两个数存储为4和25 这时候 最小的数是244 而不是2504 所以存完数字之后直接sort排序 )
3.输入注意第一位需要事先输出 后面的用printf (%.2d,)输出(会对不足前方自动补0)
4.如果没有输出直接输出0 return 0;
ac代码

#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
int a[9];
int k=0;
int main(){
	string s1;
	string s[21]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"};	
	for(int i=0;i<6;i++){
		cin>>s1;
		if(s1=="first"||s1=="a"||s1=="another"){
			a[k]=1;
			k++;
		}
		else if(s1=="both"||s1=="second"){
			a[k]=4;
			k++;
		}
		else if(s1=="third"){
			a[k]=9;
			k++;
		}
		 else for(int j=1;j<21;j++){
			if(s[j]==s1){
				a[k]=(j*j)%100;
				k++;
				break;
			}
		}	
	}
	if(k==0){
		cout<<0;
		return 0;
	}	
	sort(a,a+k-1);	
	cout<<a[0];
for(int i=1;i<k;i++){
	printf("%.2d",a[i);	
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/Stydwn/article/details/89949479