唉,这个题。我可被他弄惨了,真他x 的要命啊
开始的时候交上死循环,
严重超时
我把cin.getline 改为了getline()
就解决了
后来是wa
原来的时候没注意排序的大小写问题
把com函数改了就ok了
开始的时候交上死循环,
严重超时
我把cin.getline 改为了getline()
就解决了
后来是wa
原来的时候没注意排序的大小写问题
把com函数改了就ok了
后来一个错误弄了我一晚上的时间啊
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
using namespace std;
int rank;
struct team
{
string name;
int p, g, w, t, l, d, s, a;
};
team tea[35];
int findnum(string c)
{
for(int i = 0; i < rank; i++)
{
if(tea[i].name == c)
return i;
}
}
int scmp(string a, string b)
{
char x,y;
int l = a.size()<b.size()?a.size():b.size();
for(int i = 0; i < l; i++)
{
x = a[i] < 'a' ? a[i]+32 : a[i];
y = b[i] < 'a' ? b[i]+32 : b[i];
if(x!=y)
return x - y;
}
if(a.length() != b.length())
return a.length() - b.length();
}
int com(const void *a, const void *b)
{
team * c = (team*)a;
team * d = (team*)b;
if(c->p != d->p)return d->p - c->p;
else if(c->w != d->w)return d->w - c->w;
else if(c->d != d->d)return d->d - c->d;
else if(c->s != d->s)return d->s - c->s;
else if(c->g != d->g)return c->g - d->g; //--->该处的d->g写成饿了c->g;!!!!!
else return scmp(c->name.data(),d->name.data());
}
int main ()
{
int n;
cin>>n;
cin.ignore();
while(n--)
{
string tournament;
getline(cin,tournament);
cout<<tournament<<endl;
cin>>rank;
cin.get();
for(int i = 0; i < rank; i++)
{
getline(cin,tea[i].name);
tea[i].p = 0;
tea[i].g = 0;
tea[i].w = 0;
tea[i].t = 0;
tea[i].l = 0;
tea[i].s = 0;
tea[i].a = 0;
tea[i].d = 0;
}
int game;
cin>>game;
cin.get();
while(game--)
{
string s1, s2;
getline(cin,s1,'#');
int _w, _l;
//scanf("%d@%d#",&_w,&_l);
char ch;
cin>>_w;
cin.ignore();
cin>>_l;
cin.ignore();
//cout<<_w<<"against"<<_l<<endl;
getline(cin,s2,'\n');
int q1 = findnum(s1);
int q2 = findnum(s2);
tea[q1].g++;
tea[q1].s+=_w;
tea[q1].a+=_l;
tea[q1].d = tea[q1].s-tea[q1].a;
tea[q2].g++;
tea[q2].s+=_l;
tea[q2].a+=_w;
tea[q2].d = tea[q2].s-tea[q2].a;
if(_w == _l)
{
tea[q1].t++;
tea[q2].t++;
tea[q1].p++;
tea[q2].p++;
}
else if(_w > _l)
{
tea[q1].w++;
tea[q2].l++;
tea[q1].p+=3;
}
else
{
tea[q1].l++;
tea[q2].w++;
tea[q2].p+=3;
}
}
qsort(tea,rank,sizeof(tea[0]),com);
for(int i = 0; i < rank; i++)
{
cout<<i+1<<") "
<<tea[i].name<<" "
<<tea[i].p<<"p, "
<<tea[i].g<<"g ("
<<tea[i].w<<"-"
<<tea[i].t<<"-"
<<tea[i].l<<"), "
<<tea[i].d<<"gd ("
<<tea[i].s<<"-"
<<tea[i].a<<")"<<endl;
}
if(n)cout<<endl;
}
return 0;
}