zoukankan      html  css  js  c++  java
  • 1005 Spell It Right (20)(20 point(s))

    problem

    Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.
    
    Input Specification:
    
    Each input file contains one test case. Each case occupies one line which contains an N (<= 10^100^).
    
    Output Specification:
    
    For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.
    
    Sample Input:
    
    12345
    Sample Output:
    
    one five
    
    

    tip

    求位数上数字的和。

    anwser

    using namespace std;
    
    string GetName(int i){
    	switch(i){
    		case 0: return "zero";
    		case 1: return "one";
    		case 2: return "two";
    		case 3: return "three";
    		case 4: return "four";
    		case 5: return "five";
    		case 6: return "six";
    		case 7: return "seven";
    		case 8: return "eight";
    		case 9: return "nine";
    	}
    }
    
    int main(){
    //	freopen("test.txt", "r", stdin);
    	
    	string N;
    	int sum = 0;
    	cin>>N;
    	for(int i = 0; i < N.size(); i++){
    		sum += (int)N[i]-48;
    	}
    	if (sum == 0) {
    		cout<<GetName(sum);
    		return 0;
    	}
    //	cout<<sum;
    	vector<int> di;
    	while(sum > 0){
    		di.push_back(sum%10);
    		sum/=10;
    	}
    	reverse	(di.begin(), di.end());
    	for(size_t i = 0; i < di.size(); i++){
    		if (i == 0) cout<<GetName(di[i]);
    		else cout<<" " << GetName(di[i]);
    	}
    	return 0;
    }
    

    experience

    边界条件:

    • 非负数 有0的情况。

    时间就是生命,应该是10分钟解决的,却花了 20分钟。

  • 相关阅读:
    2021-07-12 部分集训题目题解
    2021-07-09/11 部分集训题目题解
    k8s删除Terminating状态的命名空间
    yum命令安装jenkins
    Jenkins构建docker镜像
    jenkins获取当前构建任务的构建人
    Kubernetes kubeconfig配置文件
    K8S中使用gfs当存储
    人类视觉系统对颜色和亮度的感知
    荧光的应用之全内反射荧光显微镜(TIRFM)
  • 原文地址:https://www.cnblogs.com/yoyo-sincerely/p/9265448.html
Copyright © 2011-2022 走看看