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;
}
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;
}
相关文章推荐
- Ajax & PHP without using the XmlHttpRequest Object
- Paging Database Results in ASP.NET (Prt1)(转载:http:
- 常用的HTTP头部字段的基本含义(转)
- 博客已搬家到:http://www.cnblogs.com/netWild
- windows2008下 IIS7 HTTP 错误 404.2 - Not Found 解决方法(图文)
- B3-从http头中找到X-Forwarded-For发来的客户端ip 地址
- ASP.NET中httpModules的用法和配置
- 关于httpServletRequest中方法的详细介绍
- paip. http 405 的解决..
- spring android http
- HttpClient入门
- 使用HttpWebRequest和HttpWebResponse实现模拟登录需要登陆后才可以访问的页面
- Zend_Http_Client 执行http请求 --(手册)
- http://www.cnblogs.com/heyonggang/p/3664565.html
- const 用法总结(转载)http://blog.csdn.net/zcf1002797280/article/details/7816977
- android async-http使用
- Comet:基于 HTTP 长连接的“服务器推”技术解析
- HTTP中的Get与Post区别
- ReactNative系列之十对Http的Get和Post的简单封装
- swift 3 发送 HTTP 请求函数