24h購物| | PChome| 登入
2012-04-03 13:41:54| 人氣555| 回應0 | 上一篇 | 下一篇

[UVA][Map&sstream] 11629 - Ballot evaluation

推薦 0 收藏 0 轉貼0 訂閱站台

2009/2010 ACM International Collegiate Programming Contest
University of Ulm Local Contest

Problem B: Ballot evaluation

Before the 2009 elections at the European Parliament, Bill and Ted have asked their friends to make guesses about the outcome of the ballot. Now, the results have been published, so Bill and Ted want to check who was right. But checking the results of their many friends would take a very long time, and they need the evaluation to be done by a computer. Since they are not so good at programming, they ask you for help.

Input Specification

The data provided by Bill and Ted has the following format: The first line consists of the number p of parties followed by the number g of guesses (with 1 ≤ p ≤ 50 and 1 ≤ g ≤ 10000). Then follow p lines, each line consisting of a unique party name of length ≤ 20 (only containing letters a-z, A-Z and digits 0-9) and the achieved vote percentage of this party with one digit after the decimal point. After the parties follow g lines, each consisting of a guess. A guess has the form P1 + P2 + ... + Pk COMP n, where P1 to Pk are party names, COMP is one of the comparison operators <, >, <=, >= or = and n is an integer between 0 and 100, inclusively. Each party name occurs at most once in each guess.

Output Specification

For each guess, sum up the vote percentages of the parties and compare them with the specified integer n. Then, print a line stating whether the guess was correct. See the sample output for details.

Sample Input

6 5
CDU 30.7
SPD 20.8
Gruene 12.1
FDP 11.0
DIELINKE 7.5
CSU 7.2
FDP > 11
CDU + SPD < 50
SPD + CSU >= 28
FDP + SPD + CDU <= 42
CDU + FDP + SPD + DIELINKE = 70

Sample Output

Guess #1 was incorrect.
Guess #2 was incorrect.
Guess #3 was correct.
Guess #4 was incorrect.
Guess #5 was correct.


#include <iostream>
#include <sstream>
#include <string.h>
#include <cstdio>
#include <map>
using namespace std;

int main() {
int p, q, num, sum, a, b;
scanf("%d %d", &p, &q);
char str[1000];
map<string, int> record;
while(p--) {
scanf("%s %d.%d", str, &a, &b);
record[str] = a*10+b;
}
getchar();
int Case = 0;
stringstream line;
while(q--) {
gets(str);
stringstream line(str);
printf("Guess #%d was ", ++Case);
sum = 0;
while(line >> str) {
if(strcmp(str ,"+") == 0)
continue;
if(strcmp(str ,"<") == 0) {
line >> num;
if(sum < num*10) {
puts("correct.");
} else {
puts("incorrect.");
}
break;
}
if(strcmp(str ,">") == 0) {
line >> num;
if(sum > num*10) {
puts("correct.");
} else {
puts("incorrect.");
}
break;
}
if(strcmp(str ,"<=") == 0) {
line >> num;
if(sum <= num*10) {
puts("correct.");
} else {
puts("incorrect.");
}
break;
}
if(strcmp(str ,">=") == 0) {
line >> num;
if(sum >= num*10) {
puts("correct.");
} else {
puts("incorrect.");
}
break;
}
if(strcmp(str ,"=") == 0) {
line >> num;
if(sum == num*10) {
puts("correct.");
} else {
puts("incorrect.");
}
break;
}
sum += record[str];
}
}
return 0;
}
 

台長: Morris
人氣(555) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][Greedy] 10720 - Graph Construction
此分類上一篇:[UVA] 865 - Substitution Cypher

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文