• hdu 2986 Ballot evaluation (Simulation)


    Problem - 2986

      之前在华工赛见过的一道简单的模拟,用map轻松干掉。为了精确,要全程用整型比较。轻松1y~

    代码如下:

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <string>
     6 #include <map>
     7 
     8 using namespace std;
     9 
    10 map<string, int> val;
    11 
    12 int con(char *str) {
    13     int a, b;
    14     sscanf(str, "%d.%d", &a, &b);
    15     return a * 10 + b;
    16 }
    17 
    18 bool check(int a, int b, char *p) {
    19     if (!strcmp(p, "=")) return a == b;
    20     if (!strcmp(p, "<=")) return a <= b;
    21     if (!strcmp(p, ">=")) return a >= b;
    22     if (!strcmp(p, "<")) return a < b;
    23     if (!strcmp(p, ">")) return a > b;
    24     return false;
    25 }
    26 
    27 int main() {
    28     int n, m;
    29     char buf[2][100];
    30     while (cin >> n >> m) {
    31         for (int i = 0; i < n; i++) {
    32             for (int i = 0; i < 2; i++) cin >> buf[i];
    33             val[buf[0]] = con(buf[1]);
    34         }
    35         for (int cas = 1; cas <= m; cas++) {
    36             int sum = 0;
    37             while (true) {
    38                 cin >> buf[0];
    39                 sum += val[buf[0]];
    40                 cin >> buf[0];
    41                 if (buf[0][0] != '+') break;
    42             }
    43             int x;
    44             cin >> x;
    45             cout << "Guess #" << cas << " was " << (check(sum, x * 10, buf[0]) ? "correct." : "incorrect.") << endl;
    46         }
    47     }
    48     return 0;
    49 }
    View Code

    ——written by Lyon

  • 相关阅读:
    Node.js 笔记03
    Node.js 笔记02
    Node.js 笔记01
    源代码管理工具-git
    ES6笔记01
    07_查找、软链接、打包压缩、软件安装
    06_系统信息相关命令
    oracle序列中cache和nocache
    PL/SQL规范、块、过程、函数、包、触发器
    对Xcode菜单选项的详细探索(干货)
  • 原文地址:https://www.cnblogs.com/LyonLys/p/hdu_2986_Lyon.html
Copyright © 2020-2023  润新知