http://www.acm.cs.ecnu.edu.cn/problem.php?problemid=2239
poj http://poj.org/problem?id=1805
题目的大概意思就是一些人要投票去三个地方,要注意的是同一个人如果同时有两或以上个想去的地方,那他就会弃权,其他的只要按照题目给的逻辑就可以了
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <queue> 7 #include <stack> 8 #include <vector> 9 #include <string> 10 #include <set> 11 #include <cctype> 12 #include <cstdlib> 13 #include <map> 14 #define maxn 100005 15 #define inf 0x3f3f3f 16 #define LL long long 17 using namespace std; 18 19 string name[8] = {"Anne", "Bob", "Karin", "Dave", "Charly", "Edward", "Frank"}; 20 int mark[9]; //mark用于标记是否到场 21 string stay[4] = {"cinema", "cocktail bar", "disco", "stay at the Hacienda"}; 22 char s[1005]; 23 int note[4]; //投票的 24 25 void p(string st){ 26 for (int i = 0; i < 7; i++) 27 if (st == name[i]) mark[i]++; 28 } 29 30 void init(){ 31 memset(mark, 0, sizeof(mark)); 32 memset(note, 0, sizeof(note)); 33 string st; 34 for (int i = 0; s[i]; i++){ 35 if (s[i] != ' ') st += s[i]; 36 else{ 37 p(st); 38 st = ""; 39 } 40 } 41 p(st); 42 } 43 44 void solve(){ 45 if (mark[0]) note[0]++; //Anne 46 if (mark[1]){ // Bob 47 int f1 = 0, f2 = 0; 48 if (mark[2]) f1 = 1; 49 if (mark[3] || mark[5] || !mark[0]) f2 = 1; 50 if (f1 == 1 && f2 == 0) note[2]++; 51 else if (f1 == 0 && f2 == 1) note[1]++; 52 } 53 if (mark[2]){//Karin 54 if (mark[4]) note[2]++; 55 else if (mark[0]) note[0]++; 56 else note[1]++; 57 } 58 //if (mark[3]) //Dave 59 if (mark[4]){ //Charly 60 if (mark[0]) note[0]++; 61 } 62 if (mark[5]){ //Edward 63 if (mark[0] && !mark[4]) note[1]++; 64 else note[0]++; 65 } 66 if (mark[6]){ //Frank 67 if (!mark[0] && !mark[1]) note[0]++; 68 if (mark[0]) note[2]++; 69 } 70 if (note[0] > note[1] && note[0] > note[2]) cout << stay[0] << endl; 71 else if (note[1] > note[0] && note[1] > note[2]) cout << stay[1] << endl; 72 else if (note[2] > note[0] && note[2] > note[1]) cout << stay[2] << endl; 73 else cout << stay[3] << endl; 74 } 75 76 int main(){ 77 int T; 78 cin >> T; 79 getchar(); 80 for (int cnt = 1; cnt <= T; cnt++){ 81 if (cnt != 1) printf(" "); 82 gets(s); 83 init(); 84 printf("Scenario #%d: ", cnt); 85 solve(); 86 } 87 return 0; 88 }