HDOJ I Love You Too (第一周)

来源:互联网 发布:红旗linux界面图 编辑:程序博客网 时间:2024/04/30 14:01

I Love You Too

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 11   Accepted Submission(s) : 5
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
419441814163419262237441944181416341926223
 

Sample Output
ILOVEYOUTOOVOYEUOOTIO
 

读懂了就好做了,一次A
ac代码:
#include<stdio.h>#include<stdlib.h>#include<iostream>#include<algorithm>#include<string.h>using namespace std;char s1[1050][6]={{"ABC"},{"DEF"},{"GHI"},{"JKL"},{"MNO"},{"PQRS"},{"TUV"},{"WXYZ"}};//step1char s2[4][1050]={{"QWERTYUIOPASDFGHJKLZXCVBNM"},{"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}};//step2int main(){    char num[1050],s[1050];    char last[1050];    int i,j;    while(scanf("%s",s)!=EOF)    {        int len=strlen(s);        int c=0;//step1        for(i=0;i<len;)        {            num[c++]=s1[s[i]-'0'-2][s[i+1]-'0'-1];            i+=2;        }        for(j=0;j<c;j++)        {            for(i=0;i<26;i++)            {                if(s2[0][i]==num[j])                {                    num[j]=s2[1][i];                    break;                }            }        }        int k;        if(c%2==1)        k=c/2+1;        else        k=c/2;        int l=0;        for(i=0,j=k;i<k;i++,j++)        {            last[l++]=num[i];            if(j<c)            last[l++]=num[j];        }        i=l-1;        while(i>=0)        {            printf("%c",last[i]);            i--;        }        printf("\n");    }    return 0;}


0 0
原创粉丝点击