View Code of Problem 114

#include <bits/stdc++.h>
using namespace std;

void trans(string& str,int k,int len) {
	char temp;
	for(int i=k,j=len+k-1;i<j;i++,j--) {
		temp = str[i];
		str[i] = str[j];
		str[j] = temp;
		
	}
}
int main() 
{
	string str;
	while(getline(cin,str)) {
		int len = 0;
		for(int i=0;i<str.length()+1;i++) {
			if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')) {
				len++;
			} else if(str[i-1]!=' '&& (str[i]==' '|| str[i]=='\0' )) {
				trans(str,i-len,len);
				len=0;
			}
		}
		cout<<str<<endl;
		
	}
	return 0;
 } 

Double click to view unformatted code.


Back to problem 114