题目描述
将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。
输入
输入包括一行。 第一行输入的字符串。
输出
输出转换好的逆序字符串。
样例输入
I am a student
样例输出
tneduts a ma I

分析:

关键问题在使用 getchar()回收 '/n',不然的话getline(cin,str)会将'/n'录入

//字符串的输入输出处理 
#include<iostream>
using namespace std;
int main()
{

//    cout<<endl;
int n,i=0;
cin>>n;
string str;
getchar();
while(n--){
    getline(cin,str);
    cout<<str<<endl<<endl;
}
while(cin>>str){
    cout<<str<<endl<<endl;
}
} 
View Code

相关文章:

  • 2021-10-02
  • 2021-08-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2019-11-21
猜你喜欢
  • 2021-06-01
  • 2021-06-12
  • 2022-12-23
  • 2022-01-31
相关资源
相似解决方案