1005. Spell It Right (20)

简介: #include using namespace std;int main(int argc, const char * argv[]) { string s; cin >> s; int sum = 0, len = (int)s.

#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    string s;
    cin >> s;
    int sum = 0, len = (int)s.length();
    
    for (int i = 0; i < len; i++) {
        sum += s[i] - '0';
    }
    
    string sp = to_string(sum);
    string num[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    
    cout << num[sp[0] - '0'];
    for (int i = 1; i < sp.length(); i++) {
        cout << ' ' << num[sp[i] - '0'];
    }
    
    cout << endl;
   
    return 0;
}


目录
相关文章
|
6月前
|
IDE 开发工具 Python
【Python】已解决:IndentationError: unindent does not match any outer indentation level
【Python】已解决:IndentationError: unindent does not match any outer indentation level
240 0
|
6月前
|
安全
Warning: Don’t paste code into the DevTools Console that you don’t understand or haven’t reviewed yo
Warning: Don’t paste code into the DevTools Console that you don’t understand or haven’t reviewed yo
|
AndFix
*Typo: In word 'jeesite' less... (Ctrl+F1) Spellchecker inspection helps locate typos and misspelli
*Typo: In word 'jeesite' less... (Ctrl+F1) Spellchecker inspection helps locate typos and misspelli
99 0
|
前端开发 JavaScript
brackets
brackets
67 0
|
算法 Python
LeetCode 1160. 拼写单词 Find Words That Can Be Formed by Characters
LeetCode 1160. 拼写单词 Find Words That Can Be Formed by Characters
LeetCode 1160. 拼写单词 Find Words That Can Be Formed by Characters
LeetCode 150. Evaluate Reverse Polish Notation
根据逆波兰表示法,求表达式的值。 有效的运算符包括 +, -, *, / 。每个运算对象可以是整数,也可以是另一个逆波兰表达式。
57 0
LeetCode 150. Evaluate Reverse Polish Notation
|
Android开发
The word is not correctly spelled问题
The word is not correctly spelled问题
239 0
The word is not correctly spelled问题
|
算法 Linux 测试技术
【论文阅读】(2014)Combinatorial Benders’ Cuts for the Strip Packing Problem
【论文阅读】(2014)Combinatorial Benders’ Cuts for the Strip Packing Problem
268 0
【论文阅读】(2014)Combinatorial Benders’ Cuts for the Strip Packing Problem
|
Python
Python 缩进问题-inconsistent use of tabs and spaces in indentation.原因及解决方法
Python 缩进问题-inconsistent use of tabs and spaces in indentation.原因及解决方法
6229 0
Python 缩进问题-inconsistent use of tabs and spaces in indentation.原因及解决方法
|
存储 算法
ARTS-24 字符串互异
ARTS-24 字符串互异
101 0