P1603 斯诺登的密码

题目描述

2013年X月X日,俄罗斯办理了斯诺登的护照,于是他混迹于一架开往委内瑞拉的飞机。但是,这件事情太不周密了,因为FBI的间谍早已获悉他的具体位置——但这不是最重要的——最重要的是如果要去委内瑞拉,那么就要经过古巴,而经过古巴的路在美国的掌控之中。

丧心病狂的奥巴马迫降斯诺登的飞机,搜查时却发现,斯诺登杳无踪迹。但是,在据说是斯诺登的座位上,发现了一张纸条。纸条由纯英文构成:Obama is a two five zero.(以"."结束输出,只有6个单词+一个句号,句子开头如没有大写亦为合法)这句话虽然有点无厘头,但是警官陈珺骛发现这是一条极其重要的线索。他在斯诺登截获的一台笔记本中找到了一个C++程序,输入这条句子后立马给出了相对应的密码。陈珺鹜高兴得晕了过去,身为警官的你把字条和程序带上了飞机,准备飞往曼哈顿国际机场,但是在飞机上检查的时候发现——程序被粉碎了!飞机抵达华盛顿只剩5分钟,你必须在这5分钟内编写(杜撰)一个程序,免受上司的10000000000%10大板。破译密码的步骤如下:

(1)找出句子中所有用英文表示的数字(≤20),列举在下:

正规: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

(2)将这些数字平方后%100,如00,05,11,19,86,99。

(3)把这些两位数按数位排成一行,组成一个新数,如果开头为0,就去0。

(4)找出所有排列方法中最小的一个数,即为密码。

输入格式
一个含有6个单词的句子。

输出格式
一个整型变量(密码)。如果没有符合要求的数字出现,则输出0。

输入输出样例
输入
Black Obama is two five zero .
输出
425

思路:把字符数字转化为int型,然后排序,控制输出即可。
错误点:1 与09,这种情况没有考虑到;a相当于one

这里用了strtok函数来划分字符串。当然也可以用getchar()一个一个的读取。
这里也可以用map,

map<string,int>q;
q["one"]=1,q["two"]=4;
相当于提前打表,之后在输入匹配即可
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
bool cmp(int a,int b)
{
	return a<b;
}
int main(void)
{
	char senta[100];
	int num[10];
	gets(senta);
	char *str=strtok(senta," ");
	int cot=1;
	while(str!=NULL)
	{
		if(strcmp(str,"one")==0||strcmp(str,"a")==0) num[cot++]=1;
		else if(strcmp(str,"two")==0) num[cot++]=4;
		else if(strcmp(str,"three")==0) num[cot++]=9;
		else if(strcmp(str,"four")==0) num[cot++]=16;
		else if(strcmp(str,"five")==0) num[cot++]=25;
		else if(strcmp(str,"six")==0) num[cot++]=36;
		else if(strcmp(str,"seven")==0) num[cot++]=49;
		else if(strcmp(str,"eight")==0) num[cot++]=64;
		else if(strcmp(str,"nine")==0) num[cot++]=81;
		else if(strcmp(str,"ten")==0) num[cot++]=0;
		else if(strcmp(str,"eleven")==0) num[cot++]=21;
		else if(strcmp(str,"twelve")==0) num[cot++]=44;
		else if(strcmp(str,"thirteen")==0) num[cot++]=69;
		else if(strcmp(str,"fourteen")==0) num[cot++]=96;
		else if(strcmp(str,"fifteen")==0) num[cot++]=25;
		else if(strcmp(str,"sixteen")==0) num[cot++]=56;
		else if(strcmp(str,"seventeen")==0) num[cot++]=89;
		else if(strcmp(str,"eighteen")==0) num[cot++]=24;
		else if(strcmp(str,"nineteen")==0) num[cot++]=61;
		else if(strcmp(str,"twenty")==0) num[cot++]=0;
		str=strtok(NULL," ");
	}
//	for(int i=1; i<cot; i++)
//	{
//		printf("%d",num[i]);
//	}
	sort(num+1,num+cot,cmp);
	int co=1;
	while(1)
	{
		if(num[co]==0) co++;
		else
		{
		
			for(int i=co;i<cot;i++)
			{
				if(i==co)
				{
					printf("%d",num[i]);
				}
				else
				{
					if(num[i]/10==0)
						printf("0%d",num[i]);
					else printf("%d",num[i]);
				}
			}
			break;
		}
	}
	if(cot==1||co==cot) printf("0\n");
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值