做的挺呆
#include<iostream>
using namespace std;
int main()
{
string str;
getline(cin,str);
int count=0;
for(int i=str.size()-1;i>=0;i--)
{
if(str[i]!=' ') count++;
else if(str[i]==' ')
{
int j;
if(i==0) j=0;
else j=i+1;
for(;j<=i+count;j++)
{
cout<<str[j];
}
cout<<' '; count=0;
}
if(i==0)
{
for(int j=0;j<count;j++) cout<<str[j];
}
}
return 0;
}
//闫总写法
之前一直不是很清楚while里cin输入结束是怎么系统判断的,手动输入的话可用Ctrl z
#include<iostream>
using namespace std;
int main()
{
string str[100];
int n=0;
while(cin>>str[n]) n++;
for(int i=n-1;i>=0;i--)
cout<<str[i]<<' ';
return 0;
}
//