fork download
  1. #include <iostream>
  2. #include <sstream>
  3. using namespace std;
  4.  
  5. bool ValidityCheck(const string &str)
  6. {
  7. std::istringstream iss(str);
  8. int number;
  9.  
  10. while (iss >> number) {
  11. if (number < 0 || number > 15) {
  12. return false;
  13. }
  14. }
  15.  
  16. return iss.eof();
  17. }
  18.  
  19.  
  20. int main()
  21. {
  22. string buf;
  23. while (getline(cin, buf))
  24. {
  25. if (ValidityCheck(buf))
  26. cout << buf << endl;
  27. else
  28. cout << "Invalid data" << endl;
  29. }
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 5692KB
stdin
1 2  
-3  
5  
0  
d  
15  
16  
3.1  
v7  
4  
8y  
2  
7  
stdout
1 2  
Invalid data
5  
0  
Invalid data
15  
Invalid data
Invalid data
Invalid data
4  
Invalid data
2  
7