#include <iostream>
#include <sstream>
#include <vector>
#include <ctime>
std::string removeRandomWord(const std::string& input) {
std::istringstream iss(input);
std::vector<std::string> words;
std::string word;
// Split the input string into words
while (iss >> word) {
words.push_back(word);
}
// Seed the random number generator
std::srand(std::time(0));
// Generate a random index
int randomIndex = std::rand() % words.size();
// Remove the word at the random index
words.erase(words.begin() + randomIndex);
// Reconstruct the string without the random word
std::ostringstream oss;
for (size_t i = 0; i < words.size(); i++) {
if (i != 0) {
oss << " ";
}
oss << words[i];
}
return oss.str();
}
int main() {
std::string str = "I'm not clumsy The floor just hates me";
std::string result = removeRandomWord(str);
std::cout << "str: " << str << std::endl;
std::cout << "result: " << result << std::endl;
}
/*
run:
str: I'm not clumsy The floor just hates me
result: I'm clumsy The floor just hates me
*/