Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
怎么还是WA.....#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #define Upcase(c) ((((c)>='a') && ((c)<='z'))?((c)-32):(c)) char Name[25000][100]; int Index[25000],Teams=0,snumber[25000],fnumber[25000]; void GetID(char *NowName,int *number,int style) { int i,j,k,b; i=-1;j=Teams; while (i<j-1) { k=(i+j)/2; b=strcmp(Name[Index[k]],NowName); if (!b) { number[Index[k]]++; return; } if (b>0) { j=k; } else { i=k; } } if(!style) { for (i=Teams;i>j;i--) { Index[i]=Index[i-1]; } Index[j]=Teams; strcpy(Name[Teams],NowName); number[Teams]=1; Teams++; return; } } void GetChar(char *str,int *number,int style) { int p=0,p1=0; char ch[100]; while(str[p]) { while(1) { if(Upcase(str[p])<='Z'&&Upcase(str[p])>='A') { ch[p1]=Upcase(str[p]); p1++;p++; } else if(str[p]<='9'&&str[p]>='0') { ch[p1]=str[p]; p1++;p++; } else if(str[p]=='\0') { ch[p1]='\0'; p1=0; break; } else if(str[p]==' ') { ch[p1]='\0'; p++; p1=0; break; } else p++; } if(ch[0]=='\0')return; GetID(ch,number,style); } } void output(int *num1,int *num2) { int i; double sum=0; for(i=0;i<Teams;i++) { sum+=sqrt((double)num1[i]*num2[i]); } printf("%.2lf\n",sum); } int main() { int n,i,j,quit=0; char str[255]; scanf("%d",&n); getchar(); for(i=0;i<n;i++) { if(i!=0)printf("\n"); Teams=0; memset(snumber,0,sizeof(int)*25000); memset(fnumber,0,sizeof(int)*25000); while(1) { gets(str); if(str[0]=='-')break; else GetChar(str,snumber,0); } while(1) { gets(str); if(str[0]=='-') { if(quit==0) { output(snumber,fnumber); memset(fnumber,0,sizeof(int)*25000); quit++; } else if(quit==1) { break; } } else { quit=0; GetChar(str,fnumber,1); } } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator