Skip to content

Latest commit

 

History

History
32 lines (29 loc) · 667 Bytes

C++单词翻转.md

File metadata and controls

32 lines (29 loc) · 667 Bytes

在这里插入图片描述

//Author:PanDaoxi
#include <iostream>
#include <cstring>
using namespace std;

int main(){
	const int n=501;
	char a[n];
	int len,s=0,c=0,k=0;
	cin.getline(a,n);
	len=strlen(a);
	for(int i=0;i<len;i++){
		if(a[i]==' '||i==len-1){
			c++;
			if(i==len-1) k=i;
			else k=i-1;
			for(int j=k;j>=s;j--) cout<<a[j];
			if(c==1){
				cout<<" ";
				c=0;
			} 
			s=i+1;
		}
	}
	cout<<endl;
	return 0;
}