fork download
  1. #include <string>
  2. #include <iostream>
  3. int main() {
  4. const std::string numbas = "onetwothreefourfivesixseveneightnineteneleventwelvethirfourfifsixseveneighnine";
  5. const int index[] = {0, 0, 3, 6, 11, 15, 19, 22, 27, 32, 36, 39, 45, 51, 55, 59, 62, 65, 70, 74, 78, 84, 88};
  6. int in[2]{ 0 };
  7. char trash;
  8. while (std::cin >> in[0] >> trash >> in[1])
  9. std::cout << "The time is " << numbas.substr(index[(in[0] + 11) % 12 + 1], index[(in[0] + 11) % 12 + 2] - index[(in[0] + 11) % 12 + 1]) << " " << ((in[1] < 10 && in[1] != 0) ? "oh " : "") << ((in[1] > 19) ? ((in[1] < 30) ? "twen" : numbas.substr(index[in[1]/10 + 10], index[in[1] / 10 + 11] - index[in[1] / 10 + 10])) : numbas.substr(index[in[1]], index[in[1] + 1] - index[in[1]])) << ((in[1] > 19) ? "ty " + numbas.substr(index[in[1] % 10], index[in[1] % 10 + 1] - index[in[1] % 10]) : (in[1]>12) ? "teen" : "") << " " << ((in[0] < 12) ? "am" : "pm") << std::endl;
  10. }
Success #stdin #stdout 0s 15240KB
stdin
00:00
01:30
12:05
14:01
20:29
21:00
stdout
The time is twelve  am
The time is one thirty  am
The time is twelve oh five pm
The time is two oh one pm
The time is eight twenty nine pm
The time is nine  pm