fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void cmdAdd() {
  7. int a, b;
  8.  
  9. std::cin >> a >> b;
  10. std::cout << a + b << std::endl;
  11. }
  12.  
  13. void cmdSub() {
  14. int a, b;
  15.  
  16. std::cin >> a >> b;
  17. std::cout << a - b << std::endl;
  18. }
  19.  
  20. int main() {
  21. std::string command;
  22.  
  23. while (std::cin >> command) {
  24. if (command == "add") {
  25. cmdAdd();
  26. } else if (command == "sub") {
  27. cmdSub();
  28. }
  29. }
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 16056KB
stdin
add 10 20
sub 50 90
stdout
30
-40