• hdu 2986 Ballot evaluation (模拟)


    题目

    上次比赛的题目,好长时间了。

    这几天感冒了很难受, 直到现在才整理,

    上次比赛的时候,出了各种错误,   ,,,样例都没过,题目读的也很差,今天做的时候,

    看了一下网上的,发现一个代码特别简洁,学习了一下。

    不过,在hdu交的时候,交c++会编译错误,不知道怎么回事,两次了,G++能过。

    题意:给n个字符串和它们代表的值,求下面m个式子是否成立。

    字符串对应的值有一位小数, 式子上的值是整数 (比赛的时候根本 没注意这个)

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 #include <cstring>
     5 #include <map>
     6 #include <algorithm>
     7 using namespace std;
     8 
     9 int tran(char s[])
    10 {
    11     int a, b;
    12     sscanf(s, "%d.%d", &a, &b);
    13     a = a*10+b;
    14     return a;
    15 }
    16 bool check(int a, int b, char s[])
    17 {
    18     if(strcmp(s, "<")==0) return a < b;
    19     if(strcmp(s, ">")==0) return a > b;
    20     if(strcmp(s, "<=")==0) return a <= b;
    21     if(strcmp(s, ">=")==0) return a >= b;
    22     if(strcmp(s, "=")==0) return a == b;
    23     return false;
    24 }
    25 int main()
    26 {
    27     int n, m, ca, sum, ans;
    28     char s1[25], s2[100];
    29     while(cin>>n>>m)
    30     {
    31           map<string, int>mp;
    32           getchar();
    33           while(n--)
    34           {
    35               cin>>s1>>s2;
    36               mp[s1] = tran(s2);
    37           }
    38           for(ca = 1; ca <= m; ca++)
    39           {
    40               ans = 0; sum = 0;
    41               while(1)
    42               {
    43                   scanf("%s", s1);
    44                   sum += mp[s1];
    45                   scanf("%s", s2);
    46                   if(strcmp(s2, "+")!=0)
    47                     break;
    48               }
    49               cin>>ans;
    50               ans *= 10;
    51               printf("Guess #%d was ", ca);
    52               check(sum, ans, s2)?cout<<"correct.":cout<<"incorrect.";
    53               cout<<endl;
    54           }
    55     }
    56     return 0;
    57 }
  • 相关阅读:
    OGNL与值栈
    Struts2的数据封装
    Struts2页面配置和访问servlet API
    Struts2入门介绍(二)
    Struts2 入门介绍(一)
    Hibernate批量抓取
    Problem G: STL——整理唱片(list的使用)
    STL详细介绍(更新中~~~)
    Problem E: 数量的类模板
    CF: Long Number
  • 原文地址:https://www.cnblogs.com/bfshm/p/3637448.html
Copyright © 2020-2023  润新知