http://www.codeforces.com/contest/75/problem/B
************************************************************************************************
就是一個簡單的類比題,人名按分數從大到小排,如果分數相同就按字典序排,輸出不包括自己,所以每次讀入處理時都忽略自己。可是我的code怎麼都wa???求解!
當初沒注意到題目是問跟自己有關係的,沒關係的優先順序為0!
#include <map>#include <set>#include <list>#include <queue>#include <deque>#include <stack>#include <string>#include <time.h>#include <cstdio>#include <math.h>#include <iomanip>#include <cstdlib>#include <limits.h>#include <string.h>#include <iostream>#include <fstream>#include <algorithm>using namespace std;#define LL long long#define MIN INT_MIN#define MAX INT_MAX#define PI acos(-1.0)#define FRE freopen("input.txt","r",stdin)#define FF freopen("output.txt","w",stdout)#define N 205map<string,int> mp;string me;struct node{ string str; int v;}p[N];void gao (string st) { int len = st.length(); int i,j; string a,b; a.clear();b.clear(); for (i = 0; i < len; i++) { if (st[i] == ' ')break; a += st[i]; }// i++; int v; if (st[i] == 'p') { v = 15; for (i = i + 10; i < len; i++) { if (st[i] == '\'') break; b += st[i]; } } if (st[i] == 'c') { v = 10; for (i = i + 13; i < len; i++) { if (st[i] == '\'') break; b += st[i]; } } if (st[i] == 'l') { v = 5; for (i = i + 6; i < len; i++) { if (st[i] == '\'') break; b += st[i]; } }//cout<<b<<endl; if (a == me || b == me) { if (b == me) mp[a] += v; if (a == me) mp[b] += v; } if (a != me && b != me) { if (mp.find(a) == mp.end()) mp[a] = 0; if (mp.find(b) == mp.end()) mp[b] = 0; }}bool cmp (node a, node b) { if (a.v == b.v) return a.str < b.str; return a.v > b.v;}int main () { int i,j; int n; cin>>me>>n; string str; getchar(); for (i = 0; i < n; i++) { getline(cin,str);//cout<<str<<"!"<<endl; gao(str); } map<string,int> ::iterator it; int cnt = 0; for (it = mp.begin(); it != mp.end(); it++) { p[cnt].str = it->first; p[cnt].v = it->second; cnt++; } sort(p,p+cnt,cmp); for (i = 0; i < cnt; i++) { cout<<p[i].str<<endl; } return 0;}