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


  • 相关阅读:
    JavaScript实现文本框和密码框placeholder效果(兼容ie8)
    11.24 模拟赛题解
    一句话题解集——口胡万岁
    uTools-插件化定制属于自己的工具集[免费]
    tree
    braintree 支付
    Shopify 接口调用
    TcPlayer腾讯播放器
    微信支付(WeixinJSBridge.invoke、wx.chooseWXPay)
    图片上传(二进制文件流)
  • 原文地址:https://www.cnblogs.com/aboutblank/p/2356005.html
Copyright © 2011-2022 走看看