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


  • 相关阅读:
    UINavigation Controller
    多表连接原理
    关于内存管理
    UITabBar Contoller
    网站优化HTTP应用
    网站优化ASP.net页面跳转方式优化
    网站优化缓存访问的改进
    马化腾关于产品设计与用户体验的培训(转)
    聚聚呀平台系统结构图
    网站产品支付
  • 原文地址:https://www.cnblogs.com/aboutblank/p/2356005.html
Copyright © 2020-2023  润新知