http://acm.hdu.edu.cn/showproblem.php?pid=2986
题意很简单,主要是要处理精度,最手残的是把单词拼写错了。。。
1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 #include <stdlib.h> 5 #include <iostream> 6 #include <map> 7 using namespace std; 8 const double eps=1e-8; 9 int main() 10 { 11 int n,m; 12 while(~scanf("%d%d",&n,&m)){ 13 map<string,double>p; 14 p.clear(); 15 string str; 16 double x; 17 for (int i = 1; i <= n; i++){ 18 cin>>str; 19 cin>>x; 20 int tt = int(x*10+eps); 21 p[str] = tt; 22 } 23 int o = 0; 24 while(m--){ 25 o++; 26 int ans = 0; 27 while(1){ 28 cin>>str; 29 if(str==">"||str=="<"||str==">="||str=="<="||str=="=") 30 break; 31 ans+=p[str]; 32 } 33 int k; 34 cin>>k; 35 k *=10; 36 int flag1 = 0,flag2 = 0,flag3 = 0,flag4 = 0,flag5 = 0; 37 if(str==">"){ 38 if(ans>k) 39 flag1 = 1; 40 } 41 else if (str=="<"){ 42 if (ans<k) 43 flag2 = 1; 44 } 45 else if (str==">="){ 46 if (ans>=k) 47 flag3 = 1; 48 } 49 else if (str=="<="){ 50 if (ans<=k) 51 flag4 = 1; 52 } 53 else if (str=="="){ 54 if (ans==k) 55 flag5 = 1; 56 } 57 if(flag1||flag2||flag3||flag4||flag5) 58 printf("Guess #%d was correct. ",o); 59 else 60 printf("Guess #%d was incorrect. ",o); 61 } 62 } 63 return 0; 64 }