|
#include<iostream.h>
#include<string.h>
#include<stdio.h>
int main()
{
int N;
int n;
int i,j,k,index,length,x,m;
char s[100];
cin>>N; //先输入N
cout<<endl;
for(i=0;i<N;i++)
{
cin>>n; //再输入n
for(j=0;j<n;j++)
{
gets(s);
m=0;
length=strlen(s);
for(k=0;k<length+1;k++)
if(s[k]==' '||s[k]=='\0')
{
index=k;
for(x=index-1;x>=m;x--)
{
cout<<s[x];
}
if(index!=length)
cout<<" ";
m=index+1;
}
cout<<endl;
}
if(i!=N-1)
cout<<endl;
}
return 0;
}
这个程序是输入一行字符后,反序输出
Sample Input
1
3
I am happy today
To be or not to be
I want to win the practice contest
Sample Output
I ma yppah yadot
oT eb ro ton ot eb
I tnaw ot niw eht ecitcarp tsetnoc
想问一下在C++中如何读入一行字符,题中gets(s)换成cin.getline(s,100)好像不行,有其它的方法吗?
大家帮帮忙. |
|