hdoj 2816 I Love You Too

I Love You Too

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1756    Accepted Submission(s): 1056


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>
#define MAX 1100
char s[MAX];
int a[30];
char str2[MAX];
char str5[MAX];
char str3[30]={"QWERTYUIOPASDFGHJKLZXCVBNM"};
char str4[30]={"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
char str1[20][5]={"\0","\0","ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"};
char str6[MAX],str7[MAX];
int main()
{
    int n,m,j,i,t,l1,l2,l3,l4;
    while(scanf("%s",s)!=EOF)
    {
        memset(a,0,sizeof(a));
        memset(str2,'\0',sizeof(str2));
        memset(str5,'\0',sizeof(str5));
        memset(str6,'\0',sizeof(str6));
        memset(str7,'\0',sizeof(str7));
        l1=strlen(s);
        j=0;
        for(i=0;i<l1;i=i+2,j++)
            str2[j]=str1[s[i]-'0'][s[i+1]-'1'];
        l2=strlen(str2);
        for(i=0;i<l2;i++)
        for(j=0;j<26;j++)
        {
            if(str2[i]==str3[j])
            {
                a[i]=j;
                break;
            }
        }
        for(i=0;i<l2;i++)
            str5[i]=str4[a[i]];
        int k=l2/2;
        j=0;
        if(l2&1)
        {
            for(i=l2-1;i>k;i--)
            str6[j++]=str5[i];   
            j=0;
            for(i=k;i>=0;i--)
            str7[j++]=str5[i];
       }
       else
       {
       	    for(i=l2-1;i>=k;i--)
            str6[j++]=str5[i];         
	        j=0;
            for(i=k-1;i>=0;i--)
            str7[j++]=str5[i];           
       }
        if(l2&1)
        for(i=0;i<=k;i++)
        {
            printf("%c",str7[i]);
            if(i==k)
            break;
            printf("%c",str6[i]);
        }
        else
        for(i=0;i<k;i++)
        {
            printf("%c",str6[i]);
            printf("%c",str7[i]);
        }
        printf("\n");
    }
    return 0;
}

  

posted @ 2015-07-25 16:37  非我非非我  阅读(284)  评论(0编辑  收藏  举报