https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1135
题意:给出球队的名字和比赛的信息,得出stanging
思路:字符串处理。需要注意的是多组数据记得初始化多次,以及比较字典序的时候team name是大小写补敏感的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
/* *********************************************** Author :111qqz Created Time :2016年01月26日 星期二 15时47分36秒 File Name :code/uva/10194.cpp ************************************************ */ #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <cmath> #include <cstdlib> #include <ctime> #define fst first #define sec second #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define ms(a,x) memset(a,x,sizeof(a)) typedef long long LL; #define pi pair < int ,int > #define MP make_pair using namespace std; const double eps = 1E-8; const int dx4[4]={1,0,0,-1}; const int dy4[4]={0,-1,1,0}; const int inf = 0x3f3f3f3f; const int N=1E3+5; string game[N]; map<string,int>TeamToId; struct Team { string nam; string lowname; int a,b,c,d,e,f,g,h,i; bool operator<(Team p)const { if (b>p.b) return true; if (b==p.b&&d>p.d) return true; if (b==p.b&&d==p.d&&g>p.g) return true; if (b==p.b&&d==p.d&&g==p.g&&h>p.h) return true; if (b==p.b&&d==p.d&&g==p.g&&h==p.h&&c<p.c) return true; if (b==p.b&&d==p.d&&g==p.g&&h==p.h&&c==p.c&&lowname<p.lowname) return true; //把第一个p.b写成p.d。。 return false; } }team[35]; int g,n; string touname; void init() { for ( int i = 0 ; i<=30 ; i++) { team[i].a=0; team[i].b=0; team[i].c=0; team[i].d=0; team[i].e=0; team[i].f=0; team[i].g=0; team[i].h=0; team[i].i=0; } } string tolow( string x) { int len = x.length(); for ( int i = 0 ; i < len ; i++) x[i]=tolower(x[i]); return x; } int main() { #ifndef ONLINE_JUDGE freopen("code/in.txt","r",stdin); #endif int T; cin>>T; getchar(); while (T--) { getline(cin,touname); cout<<touname<<endl; TeamToId.clear(); scanf("%d",&n); getchar(); init(); for ( int i = 0 ; i < n ; i++) { getline(cin,team[i].nam); team[i].lowname=tolow(team[i].nam); //一开始没看到大小写比较字典序的时候不敏感这条... TeamToId[team[i].nam]=i; } //check teamname input // for ( int i = 0 ; i < n ; i++) cout<<i<<" "<<team[i].lowname<<endl; //check map of teamtoid // for ( int i = 0 ; i < n ; i++) cout<<i<<""<<TeamToId[team[i].nam]<<endl; scanf("%d",&g); getchar(); for ( int i = 0 ; i < g ; i++) { getline(cin,game[i]); } //check game input // for ( int i = 0 ; i < g ; i++) cout<<i<<" "<<game[i]<<endl; for ( int i = 0 ; i < g ; i++) { int p1 = game[i].find('#'); int p2 = game[i].find('@'); int p3 = game[i].find('#',p2+1); string sformers = game[i].substr(p1+1,p2-p1-1); string slatters = game[i] .substr(p2+1,p3-p2-1); int formers,latters; sscanf(sformers.c_str(),"%d",&formers); sscanf(slatters.c_str(),"%d",&latters); string formerteam = game[i].substr(0,p1); string latterteam = game[i].substr(p3+1); int formerid = TeamToId[formerteam]; int latterid = TeamToId[latterteam]; // cout<<"i:"<<i<<" "<<formerteam<<" "<<latterteam<<endl; if (formers==latters) { team[formerid].e++; team[latterid].e++; //平局次数++ team[formerid].b++; team[latterid].b++; //平局各得1分 } if(formers>latters) { team[formerid].d++; team[latterid].f++; team[formerid].b+=3; } if (formers<latters) { team[formerid].f++; team[latterid].d++; team[latterid].b+=3; } team[formerid].h+=formers; team[latterid].h+=latters; team[formerid].c++; team[latterid].c++; team[formerid].i+=latters; team[latterid].i+=formers; //check each game // cout<<"formteam:"<<formerid<<" "<<formerteam<<endl; // cout<<"latterteam:"<<latterid<<" "<<latterteam<<endl; ok. // cout<<"formers:"<<formers<<endl; // cout<<"lattets:"<<latters<<endl; ok. } for ( int i = 0 ; i < n ; i++) team[i].g=team[i].h-team[i].i; sort(team,team+n); for ( int i = 0 ; i < n ; i++) team[i].a=i+1; for ( int i = 0 ; i < n ; i++) { printf("%d) ",team[i].a); cout<<team[i].nam<<" "; printf("%dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",team[i].b,team[i].c,team[i].d,team[i].e,team[i].f,team[i].g,team[i].h,team[i].i); } if (T) { puts(""); } } #ifndef ONLINE_JUDGE fclose(stdin); #endif return 0; } |
说点什么
您将是第一位评论人!