1 条题解
-
0
【本题解由站长编写】
把 0~20 的单词、三十/四十/五十打进表里;20~59 的数先读十位再读个位。m 为 0 时在时后面补 o'clock。按题面规则拼输出即可。
代码(C++17)
#include <bits/stdc++.h> using namespace std; string w[] = {"zero","one","two","three","four","five","six","seven","eight","nine", "ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"}; string tens[] = {"","","twenty","thirty","forty","fifty"}; string read(int x) { if (x <= 20) return w[x]; int t = x / 10, u = x % 10; return tens[t] + (u ? " " + w[u] : ""); } int main() { int h, m; cin >> h >> m; cout << read(h); if (m == 0) cout << " o'clock" << endl; else cout << " " << read(m) << endl; return 0; }
- 1
信息
- ID
- 4079
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 3
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者