PAT甲级1005题(按位加法)


1.题目介绍

1005

2.考察点,难度

字符串处理类,映射对应关系,难度易

3.解题代码

#include <iostream>
#include <string>
#include <map>
using namespace std;

int main(){
    string s,result;
    int sum=0;
    string english[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
    map<char, string> M;

    for(int i=0;i<10;i++)
        M.insert(pair<char, string>(i+'0',english[i]));

    getline(cin,s);

    for(int i=0;i<s.length();i++)
        sum+=s[i]-'0';

    result=to_string(sum);

    cout<<M[result[0]];
    for(int i=1;i<result.length();i++){
        cout<<" "<<M[result[i]];
    }
    return 0;
}

4.原题地址

https://pintia.cn/problem-sets/994805342720868352/problems/994805519074574336


文章作者: Peyton
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Peyton !
  目录