【每日一题38】1477. 拼写正确

Day38 AcWing 1477. 拼写正确

思路

  1. 模拟

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;

int main()
{
string n;
cin >> n;

int s = 0;
for (auto c : n) s += c - '0'; // 计算每一位的总和

string str = to_string(s);

char word[10][10] = {
"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine",
};

cout << word[str[0] - '0'];
for (int i = 1; i < str.size(); i ++ ) cout << ' ' << word[str[i] - '0'];

return 0;
}