题目链接
题目大意:计算所给数的数位之和,并用英语单词表述出来
注意:所给数超过int范围,用字符类型读取;格式控制;
思路:利用string读取数,利用ans读取和,再利用一个整数数组分别读取和的每一位,利用提前写好的字符串数组对比,相等直接输出英语单词
#pragma warning(disable:4996);
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<stack>
#include<math.h>
#include<vector>
using namespace std;
int num[10];
char shuzu[10][8] = { "zero","one","two","three","four","five","six","seven","eight","nine" };
int main() {
string s;
cin >> s;
int ans = 0;
for (int i = 0;i < s.size();i++)
{
int x = s[i] - '0';
ans += x;
}
int i = 0;
do{
num[i++] = ans % 10;
ans /= 10;
} while (ans != 0);
for (int t = i - 1;t >= 0;t--)
{
for (int k = 0;k < 10;k++)
{
if (k == num[t] && t == i - 1) cout << shuzu[k];
if (k == num[t] && t != i - 1)cout << " " << shuzu[k];
}
}
return 0;
}