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


  • 相关阅读:
    全局变量、局部变量
    结构体位域
    关键字(static const volatile extern sizeof)
    预处理#
    头文件<time.h>
    头文件<string.h>
    头文件<stdlib.h>
    session 入库
    php中的匿名函数和闭包
    redis 的 RDB 和 AOF 持久化的区别
  • 原文地址:https://www.cnblogs.com/aboutblank/p/2356005.html
Copyright © 2011-2022 走看看