AcWing 1477. 拼写正确
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
string english[10] ={"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int main()
{
string s;
getline(cin, s);
int res = 0;
for (auto t : s) res += t - '0';
vector<string> Res;
if (!res) printf("zero");
while (res)
{
Res.push_back(english[res % 10]);
res /= 10;
}
for (int i = Res.size() - 1; i >= 0; i -- )
{
cout << Res[i];
if (i != 0 || i != Res.size() - 1) cout << ' ';
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
getline(cin, s);
int n = 0;
for (auto t : s) n += t - '0';
s = to_string(n);
bool is_first = true;
for (auto t : s)
{
if (!is_first) cout << ' ';
is_first = false;
if (t == '0') printf("zero");
else if (t == '1') printf("one");
else if (t == '2') printf("two");
else if (t == '3') printf("three");
else if (t == '4') printf("four");
else if (t == '5') printf("five");
else if (t == '6') printf("six");
else if (t == '7') printf("seven");
else if (t == '8') printf("eight");
else if (t == '9') printf("nine");
}
return 0;
}