PiggiesGoSqueal

Untitled

Sep 1st, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <cassert>
  3. using namespace std;
  4.  
  5. string answer(int x)
  6. {
  7.     if (x%2==0)
  8.         return " is even";
  9.     else
  10.         return " is odd";
  11. }
  12. void test()
  13. {
  14.     assert(answer(0) == " is even");
  15.     assert(answer(11) == " is odd");
  16.     cout << "all test cases passed" << endl;
  17. }
  18. void kattis()
  19. {
  20.     int num, x;
  21.     cin >> num;
  22.     for (int i=0; i<num; i++)
  23.     {
  24.         cin >> x;
  25.         cout << x << answer(x) << endl;
  26.     }
  27. }
  28. int main(int argc, char* argv[])
  29. {
  30.     if (argc > 1 && strncmp(argv[1], "test", 4) == 0 )
  31.         test();
  32.     else
  33.         kattis();
  34.  
  35.     return 0;
  36. }
  37.  
  38. //cat sample.in | ./a.out
  39. //cat sample.in | ./a.out | diff -sample.ans
Advertisement
Add Comment
Please, Sign In to add comment