#include <iostream>
#include <sstream>
#include <vector>
#include <string>
std::string removeMiddleWord(const std::string& input) {
std::istringstream iss(input);
std::vector<std::string> words;
std::string word;
// Split into words
while (iss >> word) {
words.push_back(word);
}
if (words.size() <= 2)
return input;
// Middle index (0-based)
std::size_t mid = words.size() / 2;
// Remove the middle word
words.erase(words.begin() + mid);
// Rebuild the string
std::ostringstream oss;
for (std::size_t i = 0; i < words.size(); ++i) {
if (i > 0) oss << ' ';
oss << words[i];
}
return oss.str();
}
int main() {
std::string s = "c c++ java rust python";
std::cout << removeMiddleWord(s) << "\n";
}
/*
run:
c c++ rust python
*/