fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <stdexcept>
  5.  
  6. int
  7. main (int argc, char *argv[])
  8. {
  9. std::string line;
  10.  
  11. while (std::getline (std::cin, line)) {
  12. int N, M;
  13. std::istringstream iss (line);
  14.  
  15. if (!(iss >> N >> M))
  16. throw std::runtime_error ("input error #1");
  17.  
  18. std::cerr << "N = " << N << ", M = " << M << std::endl;
  19.  
  20. for (int i =0; i < M; ++i) {
  21. std::string word;
  22. int value1, value2;
  23.  
  24. if (!(iss >> word))
  25. throw std::runtime_error ("input error #2");
  26.  
  27. std::istringstream inner_iss (word);
  28.  
  29. if (inner_iss.peek () != '(' || !inner_iss.ignore () || !(inner_iss >> value1))
  30. throw std::runtime_error ("unexpected tokens; expected (, <value1>");
  31.  
  32. if (inner_iss.peek () != ',' || !inner_iss.ignore () || !(inner_iss >> value2))
  33. throw std::runtime_error ("unexpected tokens; expected , <value2>");
  34.  
  35. if (inner_iss.peek () != ')')
  36. throw std::runtime_error ("unexpected token expected )");
  37.  
  38. std::cerr << "\t value1 = " << value1 << ", value2 = " << value2 << std::endl;
  39. }
  40. }
  41. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout

Standard output is empty