[ACM]n a^o7 !
題目描述
All brave and intelligent fighters, next you will step into a distinctive battleground which is full of sweet and happiness. If you want to win the battle, you must do warm-up according to my instructions, which can make you in the best state preparing to fight. Now please relax yourself and enjoy the good moment. Before you raise your sharp sword to the enemy who guards the battleground, please allow me to tell you a true and romantic story about a samurai like you.?
Samurai hh fell in love with girl ss, who is charming and demure. He realized the truth that he must spend his remaining life with ss, and resolved to pursue the hard-won affection. One day hh wrote a letter to ss, when she opens the letter with excitement her mind was in tangle. She found herself completely not to figure out the meaning about the letter, which said that "n 55!w ! pue n a^o7 ! n paau !". ss also immersed herself in guessing the meaning of that letter for a long time because of her adore to hh. Finally she called hh to ask the meaning of the letter. On the other side of the phone, hh was too nervous to say. Gradually he calmed down himself and told ss to reverse the letter and read it. Then on both ends of the phone comes the voice at the same time "i need u i love u and i miss u".
ss wants to tell each of you however you are Brave And Skilled, you shouldn't forget to express your loyal love and romantic feelings to your prince or princess.
Now the horn sounds for battle,do it by the following input and output. I think each of you will get an "Accepted" in this battle with pleasant mood.
輸入
Input contains an integer T in the first line, and then T lines follow .Each line contains a message (only contain 'n5!wpuea^o7!' and?
' '(space)), the message's length is no more than 100.
輸出
Output the case number and the message. (As shown in the sample output)
示例輸入
2n 55!w ! pue n a^o7 ! n paau !n5!wpuea^o7示例輸出
Case 1: i need u i love u and i miss uCase 2: loveandmisu?
解題思路:
本題很有意思,相當于解密,題目中信的內容為密文,我們的任務是求明文,怎樣求呢,題目中是把信翻轉,對我們來說,1,把原來的字符換成為翻轉后我們看到的字符,2,逆序輸出。首先輸入字符串,然后遍歷每一個字符,If 語句判斷,把所有的情況都列出來,把該換的字母換掉,最后用reverse()函數顛倒字符串,輸出。
?
代碼:
#include <iostream> #include <algorithm> #include <string> using namespace std; int main() {int T,t;cin>>T;string a;for(t=0;t<=T;t++){getline(cin,a);//輸入字符串int i;if(t!=0)//把第一次屏蔽掉{for(i=0;i<a.length();i++){if(a[i]=='!')//挨個字符判斷,如果If成立,則字符變換a[i]='i';else if(a[i]=='u')//記得一定要用else if不要只寫if,因為極有可能把需要換掉的字母再換回來a[i]='n';else if(a[i]=='a')a[i]='e';else if(a[i]=='p')a[i]='d';else if(a[i]=='n')a[i]='u';else if(a[i]=='7')a[i]='l';else if(a[i]=='^')a[i]='v';else if(a[i]=='e')a[i]='a';else if(a[i]=='w')a[i]='m';else if(a[i]=='5')a[i]='s';}reverse(a.begin(),a.end());//把字符串顛倒cout<<"Case "<<t<<": "<<a<<endl;//逆序輸出}}return 0; }
?
運行截圖:
轉載于:https://www.cnblogs.com/sr1993/archive/2013/06/01/3697857.html
總結
以上是生活随笔為你收集整理的[ACM]n a^o7 !的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 王超:奇虎360MongoDB
- 下一篇: 中兴通讯应用之星一键手机电子书解决方案