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;
}


目录
相关文章
|
4月前
|
安全
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
|
6月前
|
编译器 C语言
gcc编译警告:warning: suggest parentheses around assignment used as truth value
gcc编译警告:warning: suggest parentheses around assignment used as truth value
340 0
|
11月前
|
前端开发 JavaScript
brackets
brackets
58 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
|
Android开发
The word is not correctly spelled问题
The word is not correctly spelled问题
229 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
250 0
【论文阅读】(2014)Combinatorial Benders’ Cuts for the Strip Packing Problem
HDOJ 1096 A+B for Input-Output Practice (VIII)
HDOJ 1096 A+B for Input-Output Practice (VIII)
107 0
|
数据库
When Tech Meets Love – Smarter Ways to NOT be Single
It’s that time of year again. Single’s Day (a.k.a Double 11) is just around the corner, people buying gifts for loved ones.
1629 0
When Tech Meets Love – Smarter Ways to NOT be Single
Latex "Error: File ended while scanning use of \@xdblarge"
Latex 编译时出现   Error: File ended while scanning use of \@xdblarge"   是因为少了一个 }...
2464 0