标签:des style blog http color java os io
http://acm.hdu.edu.cn/showproblem.php?pid=1225
一道超级简单的题,就因为我忘记写return,就wa好久,拜托我自己细心一点。
学习的地方:不过怎么查找字符串并返回下标
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2739 Accepted Submission(s): 785
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int t; struct node { char name[150]; int kick; int net; int score; }a[50000]; bool cmp(node b,node c) { if(b.score==c.score) { if(b.net==c.net) { if(b.kick==c.kick) return strcmp(b.name,c.name)<0?1:0; else return b.kick>c.kick; } else return b.net>c.net; } else return b.score>c.score; } int find(char ss[]) //查找字符串并返回下标 { int i; if(t==-1) { strcpy(a[0].name,ss); t=0; return t; } for(i=0;i<=t;i++) if(strcmp(a[i].name,ss)==0) return i; t++; strcpy(a[t].name,ss); return t; } int main() { int n,i,x,y,p,q; char str1[100],str2[40],str3[100]; while(~scanf("%d",&n)) { t=-1; memset(a,0,sizeof(a)); for(i=1;i<=n*(n-1);i++) { scanf("%s",str1); x=find(str1); scanf("%s",str2); scanf("%s",str3); y=find(str3); scanf("%d:%d",&p,&q); a[x].kick+=p; a[x].net+=p-q; a[y].kick+=q; a[y].net+=q-p; if(p>q) a[x].score+=3; else if(q>p) a[y].score+=3; else { a[x].score+=1; a[y].score+=1; } } sort(a,a+t+1,cmp); for(i=0;i<=t;i++) { printf("%s %d\n",a[i].name,a[i].score); } printf("\n"); } return 0; }
HDU-1225 Football Score,布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/cancangood/p/3909646.html