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

    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 (<= 10100).

    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
    #include<iostream>
    #include<stdio.h>
    using namespace std;
    int main()
    {
    int sum=0,n=0,count=0;
    char digits[101];
    char spell[101];
    for(int i=0; i<101; i++)
    {
    digits[i]='0';
    spell[i]='0';
    }
    cin>>digits;
    for(int i=0; i<101; i++)
    {
    if((int)(digits[i]-'0')<0)
    break;
    sum+=(int)(digits[i]-'0');//char to int
    }
    int temp=sum;
    if(sum==0)
    {
    cout<<"zero";
    return 0;
    }
    while(sum>0)
    {
    sum/=10;
    n++;
    }
    sprintf(spell,"%d",temp);//int to string(char[])
    while(count<n)
    {
    switch(spell[count])
    {
    case'0':
    cout<<"zero";
    break;
    case'1':
    cout<<"one";
    break;
    case'2':
    cout<<"two";
    break;
    case'3':
    cout<<"three";
    break;
    case'4':
    cout<<"four";
    break;
    case'5':
    cout<<"five";
    break;
    case'6':
    cout<<"six";
    break;
    case'7':
    cout<<"seven";
    break;
    case'8':
    cout<<"eight";
    break;
    case'9':
    cout<<"nine";
    break;
    }
    count++;
    if(count!=n)
    cout<<" ";
    }
    return 0;
    }


  • 相关阅读:
    单例模式
    json 格式
    axios 获取不到数据错误
    sprint test 添加事务回滚机制
    springboot An incompatible version [1.1.32] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]
    spring boot 启动之后404
    废了
    tomcat 部署项目到服务器
    Druid 介绍及配置
    jq 全选
  • 原文地址:https://www.cnblogs.com/aboutblank/p/2356005.html
Copyright © 2011-2022 走看看