POJ 2121 Inglish-number Translator

Source: Internet
Author: User

Inglish-number Translator
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4840 Accepted: 1894

Description

In this problem, you'll be given one or more integers in 中文版. Your task is to translate these numbers into their integer representation. The numbers can range from negative 999,999,999 to positive 999,999,999. The following is an exhaustive list of 中文版 words that your program must account for:
negative, Zero, one, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen , sixteen, seventeen, eighteen, nineteen, twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety, Hundred, Thousand, Million

Input

The input consists of several instances. Notes on input:
    1. Negative numbers is preceded by the word negative.
    2. The word "hundred" is not used when "thousand" could be. For example, are written "one thousand five Hundred", not "fifteen hundred".

The input is terminated by a empty line.

Output

The answers is expected to being on separate lines with a newline after each.

Sample Input

Sixnegative Seven hundred twenty Nineone million one hundred Oneeight Hundred fourteen thousand Twenty

Sample Output

6-7291000101814022

Source

CTU Open 2004,uva 486

AC Code:

#include <iostream> #include <algorithm> #include <cstring> #include <cstdio>using namespace    Std;int Main () {string T;    int sum=0,sum2=0;        while (cin>>t) {if (t== "negative") Putchar ('-');        else if (t== "zero") sum+=0;        else if (t== "one") sum+=1;        else if (t== "a") sum+=2;        else if (t== "three") sum+=3;        else if (t== "four") sum+=4;        else if (t== "five") sum+=5;        else if (t== "six") sum+=6;        else if (t== "seven") sum+=7;        else if (t== "eight") sum+=8;        else if (t== "nine") sum+=9;        else if (t== "ten") sum+=10;        else if (t== "eleven") sum+=11;        else if (t== "twelve") sum+=12;        else if (t== "thirteen") sum+=13;        else if (t== "fourteen") sum+=14;        else if (t== "fifteen") sum+=15;        else if (t== "sixteen") sum+=16;        else if (t== "Seventeen") sum+=17;        else if (t== "eighteen") sum+=18;        else if (t== "nineteen") sum+=19;        else if (t== "twenty") sum+=20;   else if (t== "thirty") sum+=30;     else if (t== "forty") sum+=40;        else if (t== "fifty") sum+=50;        else if (t== "sixty") sum+=60;        else if (t== "seventy") sum+=70;        else if (t== "eighty") sum+=80;        else if (t== "Ninety") sum+=90;        else if (t== "hundred") sum*=100;            else if (t== "thousand") {sum2+=sum*1000;        sum=0;            } else if (t== "million") {sum2+=sum*1000000;        sum=0;        } char C;        C=getchar ();            if (c== ' \ n ') {cout<<sum2+sum<< ' \12 ';            sum2=0;        sum=0; }} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 2121 Inglish-number Translator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.