Ballot evaluation

时间:2023-11-25 17:27:44

http://acm.hdu.edu.cn/showproblem.php?pid=2986

题意很简单,主要是要处理精度,最手残的是把单词拼写错了。。。

 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <iostream>
#include <map>
using namespace std;
const double eps=1e-;
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m)){
map<string,double>p;
p.clear();
string str;
double x;
for (int i = ; i <= n; i++){
cin>>str;
cin>>x;
int tt = int(x*+eps);
p[str] = tt;
}
int o = ;
while(m--){
o++;
int ans = ;
while(){
cin>>str;
if(str==">"||str=="<"||str==">="||str=="<="||str=="=")
break;
ans+=p[str];
}
int k;
cin>>k;
k *=;
int flag1 = ,flag2 = ,flag3 = ,flag4 = ,flag5 = ;
if(str==">"){
if(ans>k)
flag1 = ;
}
else if (str=="<"){
if (ans<k)
flag2 = ;
}
else if (str==">="){
if (ans>=k)
flag3 = ;
}
else if (str=="<="){
if (ans<=k)
flag4 = ;
}
else if (str=="="){
if (ans==k)
flag5 = ;
}
if(flag1||flag2||flag3||flag4||flag5)
printf("Guess #%d was correct.\n",o);
else
printf("Guess #%d was incorrect.\n",o);
}
}
return ;
}