【PAT甲级】1005 Spell It Right

it2024-06-22  42

题目链接:1005 Spell It Right

#include <iostream> using namespace std; int main(){ string s, english[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; int sum = 0; cin >> s; for(int i = 0; i < s.length(); i++) sum += s[i] - '0'; s = to_string(sum); while(s.size()){ cout << english[s[0]-'0']; s.erase(0,1); if(s.size()) cout << ' '; } }

 

最新回复(0)