点我看题目

题意 : 给你n个人名,每个名后边跟着一个数,然后m个式子,判断是否正确。

思路 :算是一个模拟吧,但是要注意浮点数容易丢失精度,所以要好好处理精度,不知道多少人死在精度上,不过我实在是不怎么会处理精度,所以我就让那个数变为字符串输入然后在处理,相当于乘上10,但是直接乘上10,数容易变,不知道的自己可以试一下。

  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <string>
  5. #include <map>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9. string name[] ;
  10. string score ;
  11. char ch[] ;
  12. int yun ;
  13. int main()
  14. {
  15. int p,g ,x,m;
  16. scanf("%d %d",&p,&g) ;
  17. map<string,int >mp ;
  18. for(int i = ; i < p ; i++)
  19. {
  20. cin>>name[i]>>score ;
  21. m = ;
  22. int len = score.size() ;
  23. m += score[len-]-'' ;
  24. int j;
  25. for(j = ; j < len ; j++)
  26. if(score[j] == '.') break ;
  27. int n = ;
  28. // printf("%d*\n",j) ;
  29. for(int k = j- ; k >= ; k--)
  30. {
  31. m += (score[k]-'')*n ;
  32. n = n* ;
  33. }
  34. mp[name[i]] = m ;
  35. // printf("#%d#\n",mp[name[i]]) ;
  36. }
  37. for(int i = ; i <= g ; i++)
  38. {
  39. int sum = ;
  40. while(true)
  41. {
  42. scanf("%s",ch) ;
  43. if(ch[] == '=' || ch[] == '>'||ch[] == '<')
  44. {
  45. if(ch[] == '=')
  46. yun = ;
  47. else if(ch[] == '>' && ch[] == '=' )
  48. yun = ;
  49. else if(ch[] == '<' && ch[] == '=')
  50. yun = ;
  51. else if(ch[] == '>')
  52. yun = ;
  53. else if(ch[] == '<')
  54. yun = ;
  55. break ;
  56. }
  57. if(ch[] != '+')
  58. sum += mp[ch] ;
  59. }
  60. scanf("%d",&x) ;
  61. x *= ;
  62. // printf("%d %d\n",sum,x) ;
  63. if(yun == )
  64. {
  65. if(sum > x)
  66. printf("Guess #%d was correct.\n",i) ;
  67. else printf("Guess #%d was incorrect.\n",i) ;
  68. }
  69. if(yun == )
  70. {
  71. if(sum < x)
  72. printf("Guess #%d was correct.\n",i) ;
  73. else printf("Guess #%d was incorrect.\n",i) ;
  74. }
  75. if(yun == )
  76. {
  77. if(sum == x)
  78. printf("Guess #%d was correct.\n",i) ;
  79. else printf("Guess #%d was incorrect.\n",i) ;
  80. }
  81. if(yun == )
  82. {
  83. if(sum >= x)
  84. printf("Guess #%d was correct.\n",i) ;
  85. else printf("Guess #%d was incorrect.\n",i) ;
  86. }
  87. if(yun == )
  88. {
  89. if(sum <= x)
  90. printf("Guess #%d was correct.\n",i) ;
  91. else printf("Guess #%d was incorrect.\n",i) ;
  92. }
  93. }
  94. return ;
  95. }

HDU 2986 Ballot evaluation(精度问题)的更多相关文章

  1. hdu 2986 Ballot evaluation (模拟)

    题目 上次比赛的题目,好长时间了. 这几天感冒了很难受, 直到现在才整理, 上次比赛的时候,出了各种错误,   ,,,样例都没过,题目读的也很差,今天做的时候, 看了一下网上的,发现一个代码特别简洁, ...

  2. hdu 2986 Ballot evaluation (Simulation)

    Problem - 2986 之前在华工赛见过的一道简单的模拟,用map轻松干掉.为了精确,要全程用整型比较.轻松1y~ 代码如下: #include <cstdio> #include ...

  3. Ballot evaluation

    http://acm.hdu.edu.cn/showproblem.php?pid=2986 题意很简单,主要是要处理精度,最手残的是把单词拼写错了... #include <stdio.h&g ...

  4. hdu 6288(二分法加精度处理问题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6288 题意:给出a,b,k,n可满足(n^a)*(⌈log2n⌉)^b<=k ,求最大的n值三个 ...

  5. HDU 5705 Clock (精度控制,暴力)

    题意:给定一个开始时间和一个角度,问你下一个时刻时针和分针形成这个角度是几点. 析:反正数量很小,就可以考虑暴力了,从第一秒开始暴力,直到那个角度即可,不会超时的,数目很少,不过要注意精度. 代码如下 ...

  6. hdu.. 基础二分的精度问题

    #include<stdio.h>#include<iostream>using namespace std;double f(double x){ return 8*x*x* ...

  7. hdu 1969 pie 卡精度的二分

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  8. HDU 4493 Tutor(精度处理)

    题目 #include<stdio.h> int main() { int t; double a,s; scanf("%d",&t); while(t--) ...

  9. HDU 1007 Quoit Design(二分+浮点数精度控制)

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

随机推荐

  1. JS完美运动框架

    这套框架实现了多物体,任意值,链式运动,多值运动,基本满足常见的需求. /* 功能:完美运动框架,可以实现多物体,任意值,链式运动,多值运动 版本:V1.0 兼容性:Chrome,FF,IE8+ (o ...

  2. spark处理jsonFile

    按照spark的说法,这里的jsonFile是特殊的文件: Note that the file that is offered as jsonFile is not a typical JSON f ...

  3. kettle Java Filter(表达式过滤)

  4. 对象创建型模式------Singleton(单例模式)

    地址:http://blog.csdn.net/wuzhekai1985/article/details/6665869.仅供自己参考学习. 单例模式:保证一个类仅有一个实例,并提供一个访问它的全局节 ...

  5. Android更改桌面应用程序launcher的两种方式

    http://blog.csdn.net/mdx20072419/article/details/9632779/ launcher,也就是android的桌面应用程序.下图是我正在使用的魅族手机的l ...

  6. (一)问候Spring4

    第一节:Spring 简介 Spring 作者:Rod Johnson: 官方网站:http://spring.io/ 最新开发包及文档下载地址:http://repo.springsource.or ...

  7. getScript 按需加载javascript

    $('input:button:first').click(function(aaa) { $.getScript('new.js', function() { alert('Script loade ...

  8. 12天学好C语言——记录我的C语言学习之路(Day 7)

    12天学好C语言--记录我的C语言学习之路 Day 7: 昨天进行了一天的数组学习,今天大家可以先写几个昨天的程序热热身,回顾回顾,然后今天第一个新程序也是关于数组的,比较难,准备好就开始啦! //输 ...

  9. 懒人记录 Hadoop2.7.1 集群搭建过程

    懒人记录 Hadoop2.7.1 集群搭建过程 2016-07-02 13:15:45 总结 除了配置hosts ,和免密码互连之外,先在一台机器上装好所有东西 配置好之后,拷贝虚拟机,配置hosts ...

  10. Mac或Linux中对Android抓包

    转载说明 本篇文章可能已经更新,最新文章请转:http://www.sollyu.com/mac-or-linux-android-caught/ 说明 首先要到http://www.charlesp ...