您的位置:首页 > 理论基础 > 计算机网络

http://acm.hdu.edu.cn/vcontest/vtl/problem/showproblem/vtlid/3135/problemid/1008

2012-01-07 19:18 381 查看
I Love You Too 

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

Total Submission(s): 567 Accepted Submission(s): 305 Problem Description

This is a true story. A man showed his love to a girl,but the girl didn't replied clearly ,but 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

这一题绝对可以称的上水题,,直接按题的意思顺序进行就ok了,但是我还是调试了好大一会,,,简直弱爆了。。。归其原因主要是因为string中的substr不够了解啊!!!

#include <iostream>
#include<algorithm>
#include <string>
using namespace std;
char map[10][10]={{'A','B','C'},{'D','E','F'},
{'G','H','I'},{'J','K','L'},
{'M','N','O'},{'P','Q','R','S'},
{'T','U','V'},{'W','X','Y','Z'}

};
string ss="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string s="QWERTYUIOPASDFGHJKLZXCVBNM";
int main()
{ string a;
while(getline(cin,a))
{string s1="";
for(int i=0;i<a.size();i+=2)
{int j = i;
s1.append(1,map[a[j]-'0'-2][a[j+1]-'0'-1]);

}
string s2="";
int j=0;
while(j<s1.size())
{
for(int i=0;i<s.size();++i)
if(s1[j]==s[i]) {s2.append(1,ss[i]);break;}
j++;
}
string s3="",s4="";
if(s2.size()%2==1)
{ s3=s2.substr(0,s2.size()/2+1);//截取时不包括最后一个。。。
s4=s2.substr(s2.size()/2+1,s2.size());
}
if(s2.size()%2==0)
{ s3=s2.substr(0,s2.size()/2);
s4=s2.substr(s2.size()/2,s2.size());
}
string s5="";
int len=max(s3.size(),s4.size());
for(int i=0;i<len;++i)
{ if(i<s3.size()) s5.append(1,s3[i]);
if(i<s4.size()) s5.append(1,s4[i]);
}
for(int i=s5.size()-1;i>=0;--i)
cout<<s5[i];
cout<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息