英文数字转换成为阿拉伯数字
2013-08-18 10:00
113 查看
#include <iostream> #include<string> #include<queue> #include <map> #include<fstream> using namespace std; #define DEBUG int parse(void) { #ifdef DEBUG fstream cin("G:\\book\\algorithms\\acm\\Debug\\dat.txt"); #endif queue<string> que; map<string, string> table ; table["One"] = "1"; table["Two"] = "2"; table["Three"] = "3"; table["Four"] = "4"; table["Five"] = "5"; table["Six"] = "6"; table["Seven"] = "7"; table["Eight"] = "8"; table["Nine"] = "9"; table["Zero"] = "0"; int n = 0; cin >> n; while (n-- > 0) { string tmp, input; cin >> input; int j = 0; int twice = 0; char buf[32]; int len = input.length(); for (int i = 0; i < len; i++) { char c = input[i]; if (isupper(c)) { buf[j] = '\0'; /* get a token */ tmp = buf; /* check special token */ if ("Double" == tmp) { twice = 1; } else if (1 == twice) /* check flag, do sth, clear flag */ { que.push(tmp); que.push(tmp); twice = 0; } else { que.push(tmp); } j = 0; } buf[j++] = c; } buf[j] = '\0'; tmp = buf; if (twice == 1) { que.push(tmp); que.push(tmp); twice = 0; } else que.push(tmp); que.pop(); while (!que.empty()) { //cout << que.front() << "==>" << table[que.front()] << "\n"; cout << table[que.front()] ; que.pop(); } cout << "\n"; } return 0; } int main() { return parse(); }程序有待完善: 在代码对特殊字符的处理中 采用 if else 的写法不是很好,现在只处理了一种特殊token (Double)。
如果要处理多种特殊token,而且处理方法又不相同,代码书写会变得难懂了
相关文章推荐
- 转换中文数字成为阿拉伯数字
- 将阿拉伯数组转换成为罗马数字
- Dephi阿拉伯数字转换成英文和中文大写
- 阿拉伯数字的研究
- 一亿亿以下的阿拉伯数字转中文的自定义函数
- 金额转换,阿拉伯数字转换成中国传统形式
- 输入数字的汉语拼音,每个拼音的首字母大写。输出该数字的阿拉伯数字。
- 罗马数字转换为阿拉伯数字
- 把阿拉伯数字转化成大写
- 阿拉伯数字转换为英语
- 阿拉伯数字转换为汉字
- java 实验七 之 阿拉伯整数转换为中文大写数字(注意读法)
- 0725-字符串练习:汉字时间转为阿拉伯数字时间
- js阿拉伯数字转中文大写
- 阿拉伯数字转大写汉字
- 人民币大写转阿拉伯数字
- JAVA编写 将阿拉伯数字转换成中文大写(不要Script的)
- python 中文汉字钱转成阿拉伯数字钱
- Leetcode刷题记——13. Roman to Integer(罗马数字转换阿拉伯数字)
- 无聊写个好玩的——阿拉伯数字变中文数字