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

int iterations; // Number of iteration that the code will run
string sentence; //The sentece that you want to reverse

void reverse ( int start, int end) 
{
	for ( int i = start, k = 0; k <= ((end-start)/2); i++, k++ ) {
		//swap( sentence[i], sentence[end-i] );
		/* This is a swap */
		char keep = sentence[i];
		sentence[i] = sentence[(end-k)];
		sentence[(end-k)] = keep;
		iterations++;
	}

}
 //4 - 7 time 7 - 4 = 3/2 = 1 
int main() {
	
	sentence = "Run Time Analysis";
	string origin = sentence;
	int len = sentence.length(), start = 0, end = 0;
	
	iterations = 0; //Starts from 0
	
	for ( int i = 0; i < len; i++ ) {
		if ( sentence[i] == ' '  || i == (len-1)) {
			i = (i==len-1) ? (i+1) : i;
			end = i-1;
			reverse( start, end );	
			start = i+1;
		}
		iterations++;
	}
	cout  << "Orginal sentence: " << origin << "\nResult: " << sentence << "\nLength of the sentence: " << len << "\nNumber of iterations: " << iterations << "\n";
	return 0;
}