标签:hit namespace mes == amp iostream style char clu
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.
Each input file contains one test case. Each case occupies one line which contains an N (≤10?100??).
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.
12345
one five
#include<iostream> #include<stack> #include<map> using namespace std; stack<string> st; map<char, string> mp; int main(){ string s; cin>>s; mp[‘0‘] = "zero"; mp[‘1‘] = "one"; mp[‘2‘] = "two"; mp[‘3‘] = "three"; mp[‘4‘] = "four"; mp[‘5‘] = "five"; mp[‘6‘] = "six"; mp[‘7‘] = "seven"; mp[‘8‘] = "eight"; mp[‘9‘] = "nine"; int sum = 0; for(auto c: s){ sum += (c - ‘0‘); } s = to_string(sum); int len = s.size(); for(int i = 0; i < len; ++i){ if(i == 0) cout<<mp[s[i]]; else cout<<" "<<mp[s[i]]; } return 0; }
标签:hit namespace mes == amp iostream style char clu
原文地址:https://www.cnblogs.com/LS-Joze/p/13336897.html