hdu 2986 Ballot evaluation (模拟)
上次比赛的题目,好长时间了。
这几天感冒了很难受, 直到现在才整理,
上次比赛的时候,出了各种错误, ,,,样例都没过,题目读的也很差,今天做的时候,
看了一下网上的,发现一个代码特别简洁,学习了一下。
不过,在hdu交的时候,交c++会编译错误,不知道怎么回事,两次了,G++能过。
题意:给n个字符串和它们代表的值,求下面m个式子是否成立。
字符串对应的值有一位小数, 式子上的值是整数 (比赛的时候根本 没注意这个)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std; int tran(char s[])
{
int a, b;
sscanf(s, "%d.%d", &a, &b);
a = a*+b;
return a;
}
bool check(int a, int b, char s[])
{
if(strcmp(s, "<")==) return a < b;
if(strcmp(s, ">")==) return a > b;
if(strcmp(s, "<=")==) return a <= b;
if(strcmp(s, ">=")==) return a >= b;
if(strcmp(s, "=")==) return a == b;
return false;
}
int main()
{
int n, m, ca, sum, ans;
char s1[], s2[];
while(cin>>n>>m)
{
map<string, int>mp;
getchar();
while(n--)
{
cin>>s1>>s2;
mp[s1] = tran(s2);
}
for(ca = ; ca <= m; ca++)
{
ans = ; sum = ;
while()
{
scanf("%s", s1);
sum += mp[s1];
scanf("%s", s2);
if(strcmp(s2, "+")!=)
break;
}
cin>>ans;
ans *= ;
printf("Guess #%d was ", ca);
check(sum, ans, s2)?cout<<"correct.":cout<<"incorrect.";
cout<<endl;
}
}
return ;
}
hdu 2986 Ballot evaluation (模拟)的更多相关文章
- hdu 2986 Ballot evaluation (Simulation)
Problem - 2986 之前在华工赛见过的一道简单的模拟,用map轻松干掉.为了精确,要全程用整型比较.轻松1y~ 代码如下: #include <cstdio> #include ...
- HDU 2986 Ballot evaluation(精度问题)
点我看题目 题意 : 给你n个人名,每个名后边跟着一个数,然后m个式子,判断是否正确. 思路 :算是一个模拟吧,但是要注意浮点数容易丢失精度,所以要好好处理精度,不知道多少人死在精度上,不过我实在是不 ...
- HDU 5510---Bazinga(指针模拟)
题目链接 http://acm.hdu.edu.cn/search.php?action=listproblem Problem Description Ladies and gentlemen, p ...
- HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 解题报告:问一个“M”型可以把一个矩形的平面最多分割成多少块. 输入是有n个“M",现 ...
- HDU 5965 扫雷 【模拟】 (2016年中国大学生程序设计竞赛(合肥))
扫雷 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submissi ...
- HDU 5935 Car 【模拟】 (2016年中国大学生程序设计竞赛(杭州))
Car Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))
Fraction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- hdu 4831 Scenic Popularity(模拟)
pid=4831" style="font-weight:normal">题目链接:hdu 4831 Scenic Popularity 题目大意:略. 解题思路: ...
- HDU 5538 House Building(模拟——思维)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5538 Problem Description Have you ever played the vi ...
随机推荐
- LintCode-Fast Power
Calculate the an % b where a, b and n are all 32bit integers. Example For 231 % 3 = 2 For 1001000 % ...
- C# ASP.NET系统缓存全解析
原文:http://blog.csdn.net/wyxhd2008/article/details/8076105 目录(?)[-] 系统缓存的概述 页面输出缓存 页面局部缓存 文件缓存依赖 数据库缓 ...
- 父<IFRAME>获取子页属性以及子页中<IFRAME>的方法
例子如下: 1.父页index.jsp <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "ht ...
- 【转】2-SAT题集
转自:http://blog.csdn.net/shahdza/article/details/7779369 [HDU]3062 Party1824 Let's go home3622 Bomb G ...
- C# 知识笔记
HttpContext.Request.Form.ToString() 获取Form表单中的内容 /// <summary> /// 获取 GET 提交方式值 /// </summa ...
- this指针指向的彻底理解
首先必须要说的是,this的指向在函数定义的时候是确定不了的,只有函数执行的时候才能确定this到底指向谁,实际上this的最终指向的是那个调用它的对象(这句话有些问题,后面会解释为什么会有问题,虽然 ...
- java基础知识回顾之javaIO类--File类应用:过滤器接口FilenameFilter和FileFilter
FilenameFilter和FileFilter都是用来过滤文件,例如过滤,以.jpg或者.java结尾的文件,通过看他们的源码:通过使用File类中String[] list(FilenameFi ...
- ubuntu安装google 输入法
12.04 LTS Precise sudo apt-get install ibus ibus-clutter ibus-gtk ibus-gtk3 ibus-qt4 sudo apt-get in ...
- Project Euler 82:Path sum: three ways 路径和:3个方向
Path sum: three ways NOTE: This problem is a more challenging version of Problem 81. The minimal pat ...
- C++ Primer笔记整理
1. 迭代器:迭代器是一种对象,它可以看做是游标,用来遍历标准模板库中的部分或者全部元素. 每个迭代器指向容器中确定的地址,此外,迭代器还提供一些基本操作符:*.++.==.!=.=. 2. 模板:是 ...