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;
    }


  • 相关阅读:
    linux gcc安装
    重装win7后如何恢复ubuntu引导
    Eclipse搭建Android开发环境(安装ADT,Android4.4.2)
    mysql变量使用总结
    最快得到MYSQL两个表的差集
    mysqldb
    更改时间 (时分秒)
    使用命令转移文件
    报喜啦~过了!
    Jmeter接口测试示例
  • 原文地址:https://www.cnblogs.com/aboutblank/p/2356005.html
Copyright © 2011-2022 走看看