题目
生词生句
- non-negative integer
非负整数
思路
很简单的一题,先将遍历输入的字符串累加求和,然后将sum的每个位记录下来存入栈中,再出栈,出栈的同时输出对应的英文
代码
using namespace std;
const char* str[10] = { "zero","one","two" ,"three" ,"four" ,"five" ,"six" ,"seven" ,"eight" ,"nine" };
int main()
{
string N;
cin >> N;
stack<int> s;
int sum = 0;
for (unsigned int i = 0; i < N.length(); ++i)
{
sum += (int)(N[i]-'0');
}
if (sum == 0)
{
s.push(sum);
}
while (sum != 0)
{
s.push(sum % 10);
sum /= 10;
}
cout << str[s.top()];
s.pop();
while (!s.empty())
{
cout << " " <<str[s.top()];
s.pop();
}
}