hdu-1727-Hastiness(字符处理)

来源:互联网 发布:特征向量组成的矩阵 编辑:程序博客网 时间:2024/05/19 02:00

Hastiness

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1813    Accepted Submission(s): 705


Problem Description
How many problems did you AC?
When you read this problem, don’t hasty and careless, this is also simple, haha, I didn’t cheat you.
The game over soon, WisKey starts using English begin countdown. He not only have no gene in math, but also bad in English. Fortunately, He met you who have gift in programming. So please help him to translate. 
 

Input
Give you an integer T, output T in English, and note that all of words are lower case. (0<=T<=9999)
 

Output
One answer One line.
Details see sample.
 

Sample Input
20341234123240
 

Sample Output
two thousand and thirty-fourone thousand and two hundred and thirty-fourone hundred and twenty-threetwenty-fourzero
 

题意不用多解释  看样例就很清楚。。
code
#include<cstdio>#include<iostream>#include<string>using namespace std;string str1[]={"one" ,"two","three","four","five","six","seven","eight","nine","ten"};string str2[]={"eleven" ,"twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"};string str3[]={"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};string str4[]={"zero","hundred","thousand"};int main(){    int n;    while(~scanf("%d",&n)){        int falg=0;        if(n==0) cout<<str4[0]<<endl;        else {            if(n>=1000){                int a=n/1000;                cout<<str1[a-1]<<" "<<str4[2];                n=n%1000;                falg=1;            }            if(n>=100){                if(falg==1) cout<<" and ";                int a=n/100;                cout<<str1[a-1]<<" "<<str4[1];                n=n%100;                falg=1;            }            if(n>=20){                if(falg==1) cout<<" and ";                int a=n/10;                cout<<str3[a-2];                a=n%10;                if(a!=0){                    cout<<'-'<<str1[a-1];                }            }else{                if(falg==1&&n!=0) cout<<" and ";                if(n>10) cout<<str2[n%10-1];                else if(n==10) cout<<str1[9];                else if(n!=0) cout<<str1[n-1];            }            cout<<endl;        }    }    return 0;}