fork(1) download
  1. #include <iostream>
  2. #include <functional>
  3. #include <vector>
  4. #include <string>
  5. #include <sstream>
  6. #include <algorithm>
  7. #include <unordered_map>
  8. #include <iterator>
  9. using namespace std;
  10.  
  11. using arguments = vector<string>;
  12. using command = function<void(arguments const &)>;
  13. using commands = unordered_map<string, command>;
  14.  
  15. vector<string> str_to_tokens(string const &src) {
  16. istringstream stream(src);
  17. return {
  18. istream_iterator<string>{stream},
  19. istream_iterator<string>{}
  20. };
  21. }
  22.  
  23. void print(arguments const &args) {
  24. for(auto &&arg: args) {
  25. cout << arg << " ";
  26. }
  27. cout << endl;
  28. }
  29.  
  30.  
  31. int main() {
  32. commands cmds = {
  33. {"print", print}
  34. };
  35.  
  36. string input;
  37. while(getline(cin, input)) {
  38. if(input.empty()) {
  39. continue;
  40. }
  41. auto tokens = str_to_tokens(input);
  42. auto cmd = tokens[0];
  43. cmds.at(cmd)(arguments{begin(tokens)+1, end(tokens)});
  44. }
  45. return 0;
  46. }
Success #stdin #stdout 0s 15240KB
stdin
print Ala ma dziwnego kota.
stdout
Ala ma dziwnego kota.