hdu-2816 I Love You Too

                            I Love You Too

Problem Description

This is a true story. A man showed his love to a girl,but the girl didn't replied clearly ,just gave him a Morse Code:
****-/*----/----*/****-/****-/*----/---**/*----/****-/*----/-****/***--/****-/*----/----*/**---/-****/**---/**---/***--/--***/****-/   He was so anxious that he asked for help in the Internet and after one day a girl named "Pianyi angel" found the secret of this code. She translate this code as this five steps:
1.First translate the morse code to a number string:4194418141634192622374
2.Second she cut two number as one group 41 94 41 81 41 63 41 92 62 23 74,according to standard Mobile phone can get this alphabet:GZGTGOGXNCS



3.Third she change this alphabet according to the keyboard:QWERTYUIOPASDFGHJKLZXCVBNM = ABCDEFGHIJKLMNOPQRSTUVWXYZ
So ,we can get OTOEOIOUYVL
4.Fourth, divide this alphabet to two parts: OTOEOI and OUYVL, compose again.we will get OOTUOYEVOLI
5.Finally,reverse this alphabet the answer will appear : I LOVE YOU TOO

I guess you might worship Pianyi angel as me,so let's Orz her.
Now,the task is translate the number strings.

Input
A number string each line(length <= 1000). I ensure all input are legal.
Output
An upper alphabet string.
 
SampleInput

4194418141634192622374

41944181416341926223

SampleOutput

ILOVEYOUTOO

VOYEUOOTIO

题意:给出一串长度不大于1000的数字,按每两个数字对应一个字母来解密(如图,即手机按键上的字母,如22代表B),解密后在根据解密对应的编码【3】来得到字母串,然后拆成两半(前部分不短于后部分),再按照【4】重新得到字母串,最后反序输出该字母串就ok啦。(貌似此密码很让人头疼呀。。。。别急,一步一步来,题目并不难)

#include<iostream>
using namespace std;
int main()
{
	char a[1010];
	char b[505];
	char c[252];
	char d[252];
	char ans[505];
	char x[8][5]={"KXV","MCN","OPH","QRS","ZYI","JADL","EGW","BUFT"}; //已经按照密码定义了
	while(scanf("%s",a)!=EOF)
	{
		int i,j,k;
		for(i=0,j=0;i<strlen(a);i+=2,j++)
		{	
			a[i]-='0';            //把字符转化为数字
			a[i+1]-='0';
			b[j]=x[a[i]-2][a[i+1]-1];   //求出每两个数字对应的一个字母
		}
		//要把字母串分成两个部分,而且前部分不短于后部分
		for(i=0;i<((strlen(a)/2)+1)/2;i++)
			c[i]=b[i];
		for(j=i,k=0;j<strlen(a)/2;j++,k++)
			d[k]=b[j];
		j=0;k=0;
		//再把两个字母串合并
		for(i=0;i<strlen(a)/2;i++)
		{
			if((i+1)%2!=0)
				ans[i]=c[j++];
			else
				ans[i]=d[k++];
		}
		for(i=strlen(a)/2-1;i>=0;i--)
			printf("%c",ans[i]);
		printf("\n");
	}
	return 0;
}


 

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值