POJ-2121 Inglish-Number Translator-數字英譯漢
Inglish-Number Translator
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4885 | Accepted: 1905 |
Description
In this problem, you will be given one or more integers in English. 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 English words that your program must account for:
negative, zero, one, two, 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
negative, zero, one, two, 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:
The input is terminated by an empty line.
- Negative numbers will be preceded by the word negative.
- The word "hundred" is not used when "thousand" could be. For example, 1500 is written "one thousand five hundred", not "fifteen hundred".
The input is terminated by an empty line.
Output
The answers are expected to be on separate lines with a newline after each.
Sample Input
six negative seven hundred twenty nine one million one hundred one eight hundred fourteen thousand twenty two
Sample Output
6 -729 1000101 814022
Source
CTU Open 2004,UVA 486
這個。。就是直接暴力模擬吧。。還好過了。。
/*
*Copyright (c)2015,煙臺大學計算機與控制工程學院
*All rights reserved.
*作 者:單昕昕
*完成日期:2015年8月22日
*版 本 號:v1.0
*/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
char s[100],c;
int sum=0,ans=0,flag;
while(cin>>s)
{
if(strcmp(s,"negative")==0)flag=1;
else if(strcmp(s,"zero")==0)sum+=0;
else if(strcmp(s,"one")==0)sum+=1;
else if(strcmp(s,"two")==0)sum+=2;
else if(strcmp(s,"three")==0)sum+=3;
else if(strcmp(s,"four")==0)sum+=4;
else if(strcmp(s,"five")==0)sum+=5;
else if(strcmp(s,"six")==0)sum+=6;
else if(strcmp(s,"seven")==0)sum+=7;
else if(strcmp(s,"eight")==0)sum+=8;
else if(strcmp(s,"nine")==0)sum+=9;
else if(strcmp(s,"ten")==0)sum+=10;
else if(strcmp(s,"eleven")==0)sum+=11;
else if(strcmp(s,"twelve")==0)sum+=12;
else if(strcmp(s,"thirteen")==0)sum+=13;
else if(strcmp(s,"fourteen")==0)sum+=14;
else if(strcmp(s,"fifteen")==0)sum+=15;
else if(strcmp(s,"sixteen")==0)sum+=16;
else if(strcmp(s,"seventeen")==0)sum+=17;
else if(strcmp(s,"eighteen")==0)sum+=18;
else if(strcmp(s,"nineteen")==0)sum+=19;
else if(strcmp(s,"twenty")==0)sum+=20;
else if(strcmp(s,"thirty")==0)sum+=30;
else if(strcmp(s,"forty")==0)sum+=40;
else if(strcmp(s,"fifty")==0)sum+=50;
else if(strcmp(s,"sixty")==0)sum+=60;
else if(strcmp(s,"seventy")==0)sum+=70;
else if(strcmp(s,"eighty")==0)sum+=80;
else if(strcmp(s,"ninety")==0)sum+=90;
else if(strcmp(s,"hundred")==0)sum*=100;
else if(strcmp(s,"thousand")==0)
{
ans+=sum*1000;
sum=0;
}
else if(strcmp(s,"million")==0)
{
ans+=sum*1000000;
sum=0;
}
if((c=getchar())=='\n')
{
if(flag==1)
cout<<-(ans+sum)<<endl;
else
cout<<ans+sum<<endl;
sum=ans=flag=0;
}
}
return 0;
}
這個。。就是直接暴力模擬吧。。還好過了。。
相關文章
- 詞典翻譯 英譯漢
- 中國特色詞彙漢譯英 - A
- 怎樣做英譯漢題
- 中國特色詞彙漢譯英 - M
- 中國特色詞彙漢譯英 - J
- 中國特色詞彙漢譯英 - H
- 中國特色詞彙漢譯英 - G
- 中國特色詞彙漢譯英 - D
- 中國特色詞彙漢譯英 - C
- 中國特色詞彙漢譯英 - B
- 蘋果手機漢譯英的方法蘋果
- 中國特色詞彙漢譯英 - K,L
- 中國特色詞彙漢譯英 - E, F
- 【漢譯英】不要以為是中文就看懂了呀
- 【漢譯英】翻譯當然不是一成不變的啦
- 阿拉伯-漢字-數字轉換
- PHP 將數字轉換為漢字PHP
- oracle sql去掉漢字保留數字或字母OracleSQL
- 限制HTML的input只能輸入數字、英文、漢字...HTML
- oracle 一欄位 資料存在數字和漢字,只提取數字的sqlOracleSQL
- 環宇通漢英翻譯系統3.0脫殼(lock98),有人要,胡亂寫一些。 (5千字)
- C#漢字轉漢語拼音C#
- 數字轉換為漢字大寫形式程式碼例項
- C# 校驗字串是否漢字、其他字元,數字或字元C#字串字元
- iOS 獲取漢字【簡體中文】筆畫數iOS
- 各種數學名詞的英語翻譯
- jbuilder把我jsp頁面的漢字編譯成亂碼....UIJS編譯
- java 漢字轉配音Java
- C:漢字儲存
- 只提取漢字部分
- 用Python實現阿拉伯數字轉換成中國漢字Python
- SQLSERVER中實現返回漢字筆畫數的函式;SQLServer函式
- 寫了一個數字轉成簡 / 繁體漢字的助手函式函式
- JS 漢字轉換拼音JS
- UNICODE碼轉漢字Unicode
- 漢字處理問題?
- 漢字轉拼音pl/sqlSQL
- 驗證字串是否包含英文字元、數字或者漢字程式碼例項字串字元