【MAP模拟】SDUT 1471 A + B problem
2013-02-03 22:25
441 查看
来源:点击打开链接
还是A+B,难点是会拼写英文(囧)和处理字符串。转换字符串和数字可以采用map的方程。
简要用法:map<T1(数据类型),T2(数据类型)> name(名称)
定义:可以直接使用下标name[T1的内容]来访问T2,如果T2是INT或char型的话还可以自加。。详情请见STL相关。。
还是A+B,难点是会拼写英文(囧)和处理字符串。转换字符串和数字可以采用map的方程。
简要用法:map<T1(数据类型),T2(数据类型)> name(名称)
定义:可以直接使用下标name[T1的内容]来访问T2,如果T2是INT或char型的话还可以自加。。详情请见STL相关。。
#include <iostream> #include <map> #include <stdlib.h> #include <string> using namespace std; map<string,char> tw; void initmap() { tw["zero"]='0'; tw["one"]='1'; tw["two"]='2'; tw["three"]='3'; tw["four"]='4'; tw["five"]='5'; tw["six"]='6'; tw["seven"]='7'; tw["eight"]='8'; tw["nine"]='9'; } int main() { string tar; initmap(); while(getline(cin,tar)) { int n1,n2; string c1,c2; int firstl=tar.find('+',0); int secondl=tar.find('=',0); int startpos=0; int endpos=0; for(int i=0;i<firstl;i++) { string tmp; if(tar[i]==' ') { endpos=i-1; for(int j=startpos;j<=endpos;j++) tmp+=tar[j]; startpos=endpos+2; c1+=tw[tmp]; } } startpos+=2;//挪到加号后边 for(int k=firstl+2;k<secondl;k++) { string tmp2; if(tar[k]==' ') { endpos=k-1; for(int p=startpos;p<=endpos;p++) tmp2+=tar[p]; startpos=endpos+2; c2+=tw[tmp2]; } } n1=atoi(c1.c_str()); n2=atoi(c2.c_str()); if(n1==0 && n2==0) break; else { cout<<n1+n2<<endl; } } return 0; }
相关文章推荐
- A hard Aoshu Problem HDU - 3699 模拟 map
- sdut 3567 Memory Leak 模拟
- js模拟map实现原理终极版
- 复赛模拟试题 - 收费站 Dijkstra迪杰斯特拉+二分答案法 重庆一中高2018级竞赛班第九次测试 2016.9.10 Problem 4
- Problem - 501B - Codeforces(string+map)
- Sdut 2409 The Best Seat in ACM Contest(山东省第三届ACM省赛 H 题)(模拟)
- js模拟Map
- javascript模拟map输出与去除重复项的方法
- 2016"百度之星" - 资格赛(Astar Round1) Problem D(Map)
- CodeForces - 670C Cinema (map&模拟)水
- 模拟myBatis的resultMap实现方法
- 北邮09复试模拟problem c
- ZOJ-3326-An Awful Problem【7th浙江省赛】【模拟】
- Codeforces Problem - 37B - Computer Game (贪心、模拟)
- SDUTOJ 2613 This is an A+B Problem——大数模拟
- UVA 11991 Easy Problem from Rujia Liu?(map,vector)
- HDU 1612 The Blocks Problem 模拟 不会PE代码
- 2016"百度之星" - 资格赛(Astar Round1)Problem D(map+string)
- 【[Offer收割]编程练习赛23 B】【map模拟】合并子目录
- sdut 2624 Contest Print Server (模拟)