您的位置:首页 > 其它

hdoj 2816 I Love You Too 【模拟题】

2015-05-01 21:03 295 查看

I Love You Too

[b]Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1725 Accepted Submission(s): 1037

[/b]

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.

Sample Input
4194418141634192622374
41944181416341926223


Sample Output
ILOVEYOUTOO
VOYEUOOTIO


模拟水:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
char s1[]={"QWERTYUIOPASDFGHJKLZXCVBNM"};
char s2[]={"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
char s[1010];
char a[1010],b[1010];
int top;
char map[10][5];
void solve(char c)
{
	int i,j;
	for(i=0;s1[i];i++)
	{
		if(s1[i]==c)
		{
		    s[top++]=s2[i];
			break;
		}
		
	}
}
int main()
{
	int i,j,l;
	int len;
	char str[1010];
	char c;
	strcpy(map[2],".ABC.");
	strcpy(map[3],".DEF.");
	strcpy(map[4],".GHI.");
	strcpy(map[5],".JKL.");
	strcpy(map[6],".MNO.");
	strcpy(map[7],".PQRS");
	strcpy(map[8],".TUV.");
	strcpy(map[9],".WXYZ");
	while(gets(str))
	{
		l=strlen(str);
		memset(s,'\0',sizeof(s));
		top=0;
		for(i=0;i<l;i++)
		{
			c=map[str[i]-'0'][str[i+1]-'0'];
			solve(c);
			++i;
		}
		len=strlen(s);
		if(len&1)
		len+=1;
		//printf("%s\n",s);
		memset(a,'\0',sizeof(a));
		memset(b,'\0',sizeof(b));
		for(i=0;i<len/2;i++)
		{
			a[i]=s[i];
		}
		j=0;
		for(;i<strlen(s);i++)
		{
			b[j++]=s[i];
		}
		memset(s,'\0',sizeof(s));
		top=0;
		for(i=0;i<strlen(a);i++)
		{
			if(a[i])
			s[top++]=a[i];
			if(b[i])
			s[top++]=b[i];
		}
		strrev(s);
		printf("%s\n",s);
		//printf("%s\n%s\n",a,b);
		//printf("%s\n",s);*/
	}
	return 0;
}


今天队友写的:

#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
char str[1010];
char phone[15][10]={"1","1","1ABC","1DEF","1GHI","1JKL","1MNO","1PQRS","1TUV","1WXYZ"};
char s[1010];
char ss[1010];
int main()
{
	int l,i,k,j;
	while(scanf("%s",str)!=EOF)
	{
		l=strlen(str);k=0;
		for(i=0;i<l;i+=2)
		{
			s[k++]=phone[str[i]-'0'][str[i+1]-'0'];
		}
		for(i=0;i<k;++i)
		{
			if(s[i]=='Q')s[i]='A';
			else if(s[i]=='W')s[i]='B';
			else if(s[i]=='E')s[i]='C';
			else if(s[i]=='R')s[i]='D';
			else if(s[i]=='T')s[i]='E';
			else if(s[i]=='Y')s[i]='F';
			else if(s[i]=='U')s[i]='G';
			else if(s[i]=='I')s[i]='H';
			else if(s[i]=='O')s[i]='I';
			else if(s[i]=='P')s[i]='J';
			else if(s[i]=='A')s[i]='K';
			else if(s[i]=='S')s[i]='L';
			else if(s[i]=='D')s[i]='M';
			else if(s[i]=='F')s[i]='N';
			else if(s[i]=='G')s[i]='O';
			else if(s[i]=='H')s[i]='P';
			else if(s[i]=='J')s[i]='Q';
			else if(s[i]=='K')s[i]='R';
			else if(s[i]=='L')s[i]='S';
			else if(s[i]=='Z')s[i]='T';
			else if(s[i]=='X')s[i]='U';
			else if(s[i]=='C')s[i]='V';
			else if(s[i]=='V')s[i]='W';
			else if(s[i]=='B')s[i]='X';
			else if(s[i]=='N')s[i]='Y';
			else if(s[i]=='M')s[i]='Z';
		}
		k++;
		j=k/2;i=0;
		int n=0;
		while(i<k/2||j<k-1)
		{
			if(i<k/2)ss[n++]=s[i++];
			if(j<k-1)ss[n++]=s[j++];
		}
		for(i=n-1;i>=0;--i)
			printf("%c",ss[i]);
		printf("\n");
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: