PAT甲级1005

传送门

这道题很简单的了,,也没什么好说的。

#include <iostream>
#include <string>
#include <map>
using namespace std;
map<int,string> IntToString{  
    {0,"zero"},  
    {1,"one"},  
    {2,"two"},  
    {3,"three"},  
    {4,"four"},  
    {5,"five"},  
    {6,"six"},  
    {7,"seven"},  
    {8,"eight"},  
    {9,"nine"}  
};
int main(int argc,char **argv){
	string num;
	int sum=0;
	cin>>num;
	for(auto ch : num)
		sum+=static_cast<int>(ch)-48;
	num=std::to_string(sum);
	cout<<IntToString[static_cast<int>(num[0]-48)];
	for(auto ch : num){
		if(ch!=num[0])
			cout<<" "<<IntToString[static_cast<int>(ch-48)];
	}
	return 0;
}


你可能感兴趣的:(PAT甲级1005)