Ultimate Reverse words
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
string line;
getline(cin, line);
istringstream lineStream(line);
string word;
vector<string> wordsVec;
while(lineStream >> word)
{
wordsVec.push_back(word);
}
for(vector<string>::iterator itBegin = wordsVec.begin(); itBegin != wordsVec.end(); ++itBegin)
{
for(vector<string>::iterator itEnd = wordsVec.end(); itEnd != wordsVec.begin(); --itEnd)
{
if(*itBegin == "," || *itBegin == "!" || *itBegin == ".")
continue;
if(itBegin->size() == itEnd->size())
{
swap(*itBegin, *itEnd);
}
}
}
for(int i = 0; i < wordsVec.size(); ++i)
{
string firstWord = wordsVec[0];
if(islower(firstWord[0]))
firstWord = toupper(firstWord[0]);
string nextWords = wordsVec[i];
for(int i = 0; i < nextWords.size(); ++i)
{
nextWords[i] = tolower(nextWords[i]);
}
}
for(int i = 0; i < wordsVec.size(); ++i)
{
cout << wordsVec[i] << " ";
}
return 0;
}
Swap-ването не работи нормално, toupper и tolower немога да ги накарам да работят, а за punctuation marks нямам идея как да им запазя местата. Рових се в нета, но за конкретния пример не намерих solution