hdu 1228 A + B
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=1228
A + B
Description
读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
Input
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
Output
对每个测试用例输出1行,即A+B的值.
Sample Input
one + two =
three four + five six =
zero seven + eight nine =
zero + zero =
Sample Output
3
90
96
字符串水题。。
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<map>
#include<set>
using std::map;
using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
const int Max_N = ;
typedef unsigned long long ull;
map<string, int> rec;
void init() {
rec["zero"] = ;
rec["one"] = ;
rec["two"] = ;
rec["three"] = ;
rec["four"] = ;
rec["five"] = ;
rec["six"] = ;
rec["seven"] = ;
rec["eight"] = ;
rec["nine"] = ;
}
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
init();
int a, b, f;
char str[], buf[];
while (gets(buf)) {
a = b = f = ;
char *p = buf;
while (true) {
if (*p == ' ') { p++; continue; }
sscanf(p, "%s", str);
if (!strcmp(str, "=")) break;
if (!f && strcmp(str, "+")) a = a * + rec[str];
if (!strcmp(str, "+") || f) {
if (!strcmp(str, "+")) { f = , p++; continue; }
b = b * + rec[str];
}
p = p + strlen(str);
}
if (!(a + b)) break;
printf("%d\n", a + b);
}
return ;
}
hdu 1228 A + B的更多相关文章
- 题解报告:hdu 1228 A+B(字符串)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1228 Problem Description 读入两个小于100的正整数A和B,计算A+B. 需要注意 ...
- 【HDU 1228】A + B
题 Description 读入两个小于100的正整数A和B,计算A+B. 需要注意的是:A和B的每一位数字由对应的英文单词给出. Input 测试输入包含若干测试用例,每个测试用例占一行,格式 ...
- hdu 1228
Description 读入两个小于100的正整数A和B,计算A+B. 需要注意的是:A和B的每一位数字由对应的英文单词给出. Input 测试输入包含若干测试用例,每个测试用例占一行,格式为& ...
- hdu 1228 A+B 字符串处理 超级大水题
中文意思不解释. 很水,我本来想用switch处理字符串,然后编译不通过...原来switch只能处理整数型的啊,我都忘了. 然后就有了很挫的一大串if代码了... 代码: #include < ...
- HDU 1228 A + B 浙江大学研究生冠军
Problem Description 读入两个小于100的正整数A和B,计算A+B. 须要注意的是:A和B的每一位数字由相应的英文单词给出. Input 測试输入包括若干測试用例,每一个測试用例 ...
- HDU 1228(字符串处理)
题意是将所给算式求出结果. 用的方法非常麻烦,开始没考虑到零也需要处理,以为遇上零直接跳过即可,知道发现零可以占位,比如 one zero 值为 10 而不是 1…… 代码如下: #include & ...
- HDU 1228 字符串到数字的转化
一道水题,练练字符串的输入输出 #include <cstdio> #include <cstring> using namespace std; ] , s2[]; int ...
- HDU 1698 & UESTC 1228 Just a hook
算是线段树中的一道水题了,必须用到懒操作,否则会超时.或者也可以刚开始不计算和,只更新节点,最后算整个线段的颜色和. 1.懒操作法 /* 908ms 3448KB in HDU OJ*/ #inclu ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
随机推荐
- Laxcus大数据管理系统2.0(10)- 第八章 安全
第八章 安全 由于安全问题对大数据系统乃至当前社会的重要性,我们在Laxcus 2.0版本实现了全体系的安全管理策略.同时我们也考虑到系统的不同环节对安全管理的需求是不一样的,所以有选择地做了不同的安 ...
- python字符串常用操作方法
python字符串操作常用操作,如字符串的替换.删除.截取.复制.连接.比较.查找.分割等,需要的朋友可以参考下. 1.去除空格str.strip():删除字符串两边的指定字符,括号的写入指定字符,默 ...
- Leetcode005 Longest Palindromic Substring
o(n)算法地址:http://blog.163.com/zhaohai_1988/blog/static/2095100852012716105847112/ /* pivot varies whe ...
- javaSE27天学习目录
第一阶段(java基础知识) 计算机基础知识 Java开发环境的搭建和应用 机制转换 有符号数据表示法(原码.反码.补码) Java语句基础(关键字.标识符.注释.常量.变量.数据类型.运算符) ...
- placeholder插件及placeholder默认颜色修改
$.fn.placeHolder = function(){ $(this).each(function(i, el) { var self = $(el); if ($.browser.msie & ...
- Oracle数据库中的Function调用参数问题
在工作中用到了Oracle数据库,需要调用Oracle的Function,Function返回的游标和结果都是通过参数来获取的 比如Function定义如下: , intype, ininttype) ...
- Copying Rowsets
I find that you often need to create and manipulate standalone rowsets. Sometimes you can get the da ...
- MongoDB 相关下载
MongoDB 下载:http://www.mongodb.org/ 本实例中MongoDB的C#驱动,支持linq:https://github.com/samus/mongodb-csharp M ...
- Web serviser请求通道在等待 00:00:59.6479648 以后答复时超时。增加传递给请求调用的超时值,或者增加绑定上的 SendTimeout 值。分配给此操作的时间可能是更长超时的一部分。
可以把sendTimeout调长一点试试 .net webService 中: 设置这些参数,延长连接时间, closeTimeout="00:10:00" openTimeout ...
- js 获取当天23点59分59秒 时间戳 (最简单的方法)
js 获取当天23点59分59秒 时间戳 (最简单的方法) new Date(new Date(new Date().toLocaleDateString()).getTime()+24*60*60* ...