poj 2121 Inglish-Number Translator
2013-12-21 11:28
274 查看
Inglish-Number Translator
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
Input
The input consists of several instances. Notes on input:
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
Sample Output
Source
CTU Open 2004,UVA 486
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4380 | Accepted: 1703 |
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
Input
The input consists of several instances. Notes on input:
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
#include <iostream> #include <sstream> #include <string> #include <map> using namespace std; map<string, int> dict; int main() { // init dict["zero"] = 0; dict["one"] = 1; dict["two"] = 2; dict["three"] = 3; dict["four"] = 4; dict["five"] = 5; dict["six"] = 6; dict["seven"] = 7; dict["eight"] = 8; dict["nine"] = 9; dict["ten"] = 10; dict["eleven"] = 11; dict["twelve"] = 12; dict["thirteen"] = 13; dict["fourteen"] = 14; dict["fifteen"] = 15; dict["sixteen"] = 16; dict["seventeen"] = 17; dict["eighteen"] = 18; dict["nineteen"] = 19; dict["twenty"] = 20; dict["thirty"] = 30; dict["forty"] = 40; dict["fifty"] = 50; dict["sixty"] = 60; dict["seventy"] = 70; dict["eighty"] = 80; dict["ninety"] = 90; dict["hundred"] = 100; dict["thousand"] = 1000; dict["million"] = 1000000; int result, curr, last; string str; istringstream iss; while (getline(cin, str, '\n')) { if (str == "") break; last = result = 0; iss.str(str); iss.clear(); while (iss >> str) { if (str == "negative") { cout << '-'; continue; } curr = dict[str]; if (curr > 100) { if (last > curr) result = result / last * last + (result % last * curr); else result *= curr; last = curr; } else if (curr == 100) { if (last > 100) result = result / last * last + (result % last * 100); else result *= 100; } else result += curr; } cout << result << endl; } return 0; }
相关文章推荐
- poj 2121 Inglish-Number Translator(模拟)
- POJ-2121 Inglish-Number Translator-数字英译汉
- poj 2121——Inglish-Number Translator
- POJ 2121 Inglish-Number Translator
- poj 2121 Inglish-Number Translator 将英文翻译成罗马数字
- POJ 2121 Inglish-Number Translator 笔记
- poj 2121 Inglish-Number Translator
- POJ 2121 Inglish-Number Translator
- poj 2121-Inglish-Number Translator
- POJ2121——Inglish-Number Translator
- (字符串的模式匹配4.7.12)POJ 2121 Inglish-Number Translator(将英文数字转换成阿拉伯数字)
- POJ2121 ZOJ2311 Inglish-Number Translator【map+字符串比较+水题】
- POJ 2121 Inglish-Number Translator
- poj 2121 Inglish-Number Translator
- POJ 2121 English-Number Translator (散列)
- poj2121
- poj2121
- poj2121 模拟
- Command Network POJ - 3164 + Ice_cream’s world II HDU - 2121
- poj 2121 && poj 2403