n a^o7 !
Time Limit: 1000MS Memory limit: 65536K
题目描述
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
大意:字符串密码解密,倒过来解,只包括 n5!wpuea^o7!与空格
代码:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; char str[105]; int main() { int n; cin>>n; getchar(); for(int i=1; i<=n; i++) { gets(str); int len=strlen(str); cout<<"Case "<<i<<": "; for(int j=len-1; j>=0; j--) { if(str[j]=='n') cout<<"u"; else if(str[j]=='5') cout<<"s"; else if(str[j]=='!') cout<<"i"; else if(str[j]=='w') cout<<"m"; else if(str[j]=='p') cout<<"d"; else if(str[j]=='u') cout<<"n"; else if(str[j]=='e') cout<<"a"; else if(str[j]=='a') cout<<"e"; else if(str[j]=='^') cout<<"v"; else if(str[j]=='o') cout<<"o"; else if(str[j]=='7') cout<<"l"; else if(str[j]==' ') cout<<" "; } cout<<endl; } return 0; }
总结:
关于getchar用法:
1.从缓冲区读走一个字符,相当于清除缓冲区 此处:2.前面的cin/scanf()在读取输入时会在缓冲区中留下一个字符'\n'(输入完n的值后按回车键所致),所以如果不在此加一个getchar()把这个回车符取走的话,gets()就不会等待从键盘键入字符,而是会直接取走这个“无用的”回车符,从而导致读取有误 3. getchar()是在输入缓冲区顺序读入一个字符(包括空格、回车和Tab) getchar()使用不方便,解决方法: (1)使用下面的语句清除回车: while(getchar()!='\n'); (2)用getche()或getch()代替getchar(),其作用是从键盘读入一个字符(不用按回车),注意要包含头文件<conio.h> 4. getchar()是stdio.h中的库函数,它的作用是从stdin流中读入一个字符,也就是说,如果stdin有数据的话不用输入它就可以直接读取了,第一次getchar()时,确实需要人工的输入,但是如果你输了多个字符,以后的getchar()再执行时就会直接从缓冲区中读取了。 实际上是 输入设备->内存缓冲区->程序getchar 你按的键是放进缓冲区了,然后供程序getchar 你有没有试过按住很多键然后等一会儿会滴滴滴滴响,就是缓冲区满了,你后头按的键没有存进缓冲区. 键盘输入的字符都存到缓冲区内,一旦键入回车,getchar就进入缓冲区读取字符,一次只返回第一个字符作为getchar函数的值,如果有循环或足够多的getchar语句,就会依次读出缓冲区内的所有字符直到'\n'.要理解这一点,之所以你输入的一系列字符被依次读出来,是因为循环的作用使得反复利用getchar在缓冲区里读取字符,而不是getchar可以读取多个字符,事实上getchar每次只能读取一个字符.如果需要取消'\n'的影响,可以用getchar();来清除,这里getchar();只是取得了'\n'但是并没有赋给任何字符变量,所以不会有影响,相当于清除了这个字符.还要注意的是这里你在键盘上输入ssss看到的回显正是来自于getchar的作用,如果用getch就看不到你输入了什么.