fork download
  1. #include <iostream>
  2. using namespace std;
  3. // #include <iostream>
  4. // using namespace std;
  5.  
  6. struct table
  7. {
  8. int idx;
  9. char text[20];
  10.  
  11. };
  12.  
  13. struct table data[] =
  14. {
  15. {0, "Goodnight"},
  16. {4, "Goodmorning"},
  17. {12, "Goodafternonn"},
  18. {18, "Goodevening"},
  19. {23, "Goodnight"}
  20. };
  21.  
  22. int main()
  23. {
  24. int n;
  25. while (1)
  26. {
  27. cout << "何時(0~23)";
  28. cin >> n;
  29. if (n == -1)return 0;
  30. if ((n < 0) || (n > 23))continue;
  31. for (int i = sizeof(data) / sizeof(data[0]); --i >= 0;)
  32. {
  33. if (n >= data[i].idx)
  34. {
  35. cout << data[i].text << endl;
  36. break;
  37. }
  38. }
  39. }
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 3300KB
stdin
0
5
10
15
20
25
-5
-1
stdout
何時(0~23)Goodnight
何時(0~23)Goodmorning
何時(0~23)Goodmorning
何時(0~23)Goodafternonn
何時(0~23)Goodevening
何時(0~23)何時(0~23)何時(0~23)