美文网首页
2019-08-27 A1005 Spell It Right

2019-08-27 A1005 Spell It Right

作者: JO炮 | 来源:发表于2019-08-27 17:33 被阅读0次

也是一道相对简单的题目,这道题容易出错的点是字符串与整型的转换:

    for(int i = 1; i < re.length(); i++){
        cout << " " << op[re[i] - '0'];
    }

不要忘记op[re[i]] - '0'

using namespace std;
int main() {
    string s, re;
    string op[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    cin >> s;
    int t = 0;
    for(int i = 0; i < s.length(); i++){
        t += (s[i] - '0');
    }
    re = to_string(t);
    cout << op[re[0] - '0'];
    for(int i = 1; i < re.length(); i++){
        cout << " " << op[re[i] - '0'];
    }
    return 0;
}

相关文章

  • 2019-08-27 A1005 Spell It Right

    也是一道相对简单的题目,这道题容易出错的点是字符串与整型的转换: 不要忘记op[re[i]] - '0'。

  • PAT A1005 Spell It Right (20)

    PAT A1005 Spell It RightGiven a non-negative integer N, y...

  • A1005 Spell It Right (20分).cpp

    考察:数字和转为单个位的英文单词输出 learn && wrong:1、数组老是不给名字!以及老是用错数组的名字,...

  • 1005 Spell It Right

    1005 Spell It Right (20)(20 分) Given a non-negative integ...

  • 1005 Spell It Right

    题目简述 Given a non-negative integer N, your task is to comp...

  • 1005 Spell It Right

    题目 输入一个数字N,N<=10^100。将各位数字相加,最后输出相加和的各位数字的英文,两个连续的单词之间必须有...

  • PAT甲级1005

    1005 Spell It Right (20分)Given a non-negative integer N, ...

  • 【PAT A1005】

    1005 Spell It Right (20)(20 分)Given a non-negative intege...

  • A_1005

    1005 Spell It Right (20)(20 分) Given a non-negative integ...

  • PAT 1005 Spell It Right (20 分)

    PAT 1005 Spell It Right (20 分) Given a non-negative integ...

网友评论

      本文标题:2019-08-27 A1005 Spell It Right

      本文链接:https://www.haomeiwen.com/subject/wkmdectx.html