【九度OJ】:1010
来源:互联网 发布:制造业erp软件 编辑:程序博客网 时间:2024/06/06 00:46
题意:
通俗一点来说就是将字符串解析成数字并且求和
思路:
跟上一题一样,需要先解析成两个字符串数,然后求和,方法用到了String类的assign函数,其他的就是将字符串对应到数字上去,这种算法很简单,这里就不细讲了
AC代码:
#include <iostream>#include <string>using namespace std;int getnum(string s){ if(s=="zero"){ return 0; } if(s=="one"){ return 1; } if(s=="two"){ return 2; } if(s=="three"){ return 3; } if(s=="four"){ return 4; } if(s=="five"){ return 5; } if(s=="six"){ return 6; } if(s=="seven"){ return 7; } if(s=="eight"){ return 8; } if(s=="nine"){ return 9; }}int split(string s){ string s1,s2; int a,b; for(int i=0;i<s.length();i++){ if(s[i]==' '){ s1.assign(s,0,i); s2.assign(s,i+1,s.length()-i); a = getnum(s1)*10; b = getnum(s2); return a+b; } } return getnum(s); //没有就直接返回}int main(){ string s,s1,s2; int a,b; while(getline(cin,s,'\n')){ for(int i=0;i<s.length();i++){ if(s[i]=='+'){ s1.assign(s,0,i-1); s2.assign(s,i+2,(s.length()-4-i)); } } //cout<<s1<<""<<s2<<"1"<<endl; if(s1=="zero" && s2=="zero"){ return 0; } a = split(s1); b = split(s2); cout<<a+b<<endl; } return 0;}
0 0
- 九度oj 1010
- 九度OJ 1010
- 【九度OJ】:1010
- 【九度OJ】1010【模拟】
- 九度OJ 1010 java
- 【九度OJ】:九度OJ 1050
- 【九度OJ】:九度OJ 1053
- 【九度OJ】:九度OJ 1056
- 【九度OJ】:九度OJ 1059
- 【九度OJ】:九度OJ 1206
- 九度OJ 题目1010:A + B
- 九度OJ 1010 A+B
- 九度OJ-题目1010:A + B
- 九度OJ-1010-A+B
- 九度OJ 1010 A+B
- 九度OJ 题目1010:A + B
- 九度OJ-题目1010:A+B
- 九度oj A+B 1010,1015
- Git与Repo入门
- mysql 10038错误
- 利用Python实现堆排序
- 在Android String文件中使用CDATA
- BZOJ1547 周末晚会
- 【九度OJ】:1010
- Linux使用Shell脚本实现ftp的自动上传下载
- Objective-C 编程全解-第15章 消息发送模式 上
- 空间波(space wave)
- 解决Eclipse无法自动编译项目
- Apache Commons工具集简介
- MySQL数据库复制Master-Slave架构分析
- NodeMCU教程 http请求获取Json中文乱码解决方案
- Android硬件抽象层(HAL)概要介绍和学习计划