字符串操作
来源:互联网 发布:linux samba rpm 下载 编辑:程序博客网 时间:2024/06/05 01:15
题目:给定一串英文字符串,输出其对应的数字
代码:
#include <iostream>#include <cstring>#include <map>#include <strstream>#include <string>#include <cstdio>using namespace std;int main(){ //freopen("in.txt","r",stdin); char line[256]; int ans; map<string,int>entod; entod[string("zero")] = 0; entod[string("one")] = 1; entod[string("two")] = 2; entod[string("three")] = 3; entod[string("four")] = 4; entod[string("five")] = 5; entod[string("six")] = 6; entod[string("seven")] = 7; entod[string("eight")] = 8; entod[string("nine")] = 9; entod[string("ten")] = 10; entod[string("eleven")] = 11; entod[string("twelve")] = 12; entod[string("thirteen")] = 13; entod[string("fourteen")] = 14; entod[string("fifteen")] = 15; entod[string("sixteen")] = 16; entod[string("seventeen")] = 17; entod[string("eighteen")] = 18; entod[string("nineteen")] = 19; entod[string("twenty")] = 20; entod[string("thirty")] = 30; entod[string("forty")] = 40; entod[string("fifty")] = 50; entod[string("sixty")] = 60; entod[string("seventy")] = 70; entod[string("eighty")] = 80; entod[string("ninety")] = 90; while(cin.getline(line,256)) { int len = strlen(line); if(len == 0) continue; istrstream istr(line,len); string en; int add = 0; ans = 0; while(istr >> en) { if(en == "negative") cout << "-"; if(en == "hundred") add *= 100; if(en == "thousand") { ans += add * 1000; add = 0; } if(en == "million") { ans += add; ans *= 1000000; add = 0; } add += entod[en]; } ans += add; cout << ans << endl; } return 0;}
- 字符串操作
- 字符串操作
- 操作字符串
- 字符串操作
- 字符串操作
- 字符串操作
- 字符串操作
- 字符串操作
- 字符串操作
- 字符串操作
- 字符串操作
- 字符串操作
- 字符串操作
- 字符串操作
- 字符串操作
- 字符串操作
- 字符串操作
- 字符串操作
- XML解析
- 顺序堆栈
- Go语言入门系列之安装及HelloWorld
- gvim+插件开发,体验
- 【*】POJ-3899(数论很难)(Lucky Numbers——统计)
- 字符串操作
- javabean的继承与反射
- 嵌入式面试题2
- bash: ./configure: /bin/sh^M: bad interpreter: No such file or directory
- DHCP Options
- 链式堆栈
- 关于 default-action-ref 的一个BUG
- Boost::asio范例分析 服务端
- OSG坐标系解释????????