点此查看所有题目集
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.
Input Specification:
Each input file contains one test case. Each case occupies one line which contains an N (≤10^100).
Output Specification:
For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.
简单模拟,将给定的字符串的各个位置相加,用字符串的方式输出和。文章来源:https://www.toymoban.com/news/detail-650284.html
#include <bits/stdc++.h>
using namespace std;
void get (int x)
{
if (x==0) cout << "zero";
if (x==1) cout << "one";
if (x==2) cout << "two";
if (x==3) cout << "three";
if (x==4) cout << "four";
if (x==5) cout << "five";
if (x==6) cout << "six";
if (x==7) cout << "seven";
if (x==8) cout << "eight";
if (x==9) cout << "nine";
}
int main()
{
string s;
cin >> s;
int sum = 0;
for (int i = 0 ;i<s.length();i++)
{
sum+=s[i]-48;
}
string t = to_string(sum);
for(int i = 0; i < t.size(); i++) {
if(i != 0) putchar(' ');
get(t[i]-48);
}
return 0;
}
文章来源地址https://www.toymoban.com/news/detail-650284.html
到了这里,关于PAT (Advanced Level) 甲级 1005 Spell It Right的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!