uva 10194 Football (aka Soccer)

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=1135 题意:给出球队的名字和比赛的信息,得出stanging 思路:字符串处理。需要注意的是多组数据记得初始化多次,以及比较字典序的时候team name是大小写补敏感的。

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