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<iostream.h> #include<stdio.h> void quicksort(char *b,char *e,int *d,int left,int right) { int i=left,j=right; int tempp=d[i]; char tempb=b[i]; char tempe=e[i]; while(i<j) { while(d[i]>tempp && j>i) j=j-1; if(j>i) { d[i]=d[j]; b[i]=b[j]; e[i]=e[j]; i=i+1; } while(d[i]<=tempp && j>i) i=i+1; if(i<j) { d[j]=d[i]; b[j]=b[i]; e[j]=e[i]; j=j-1; } } d[i]=tempp; b[i]=tempb; e[i]=tempe; if(left<i-1) quicksort(b,e,d,left,i-1); if(i+1<right) quicksort(b,e,d,i+1,right); } void main() { int n,m,t,d[730],count,sum; char c,s,b[730],e[730]; while(cin>>n) { int a[30]={0}; if(n==0) break; count=0; sum=0; for(int j=0;j<n-1;j++) { // getchar(); cin>>c>>m; for(int i=0;i<m;i++) { cin>>s>>t; b[count]=c; e[count]=s; d[count]=t; count++; } } // for(int k=0;k<count;k++) // cout<<b[k]<<" "<<e[k]<<" "<<d[k]<<endl; quicksort(b,e,d,0,count-1); // for(k=0;k<count;k++) // cout<<b[k]<<" "<<e[k]<<" "<<d[k]<<endl; for(int i=0;i<count;i++) { if(a[b[i]-65]==0 || a[e[i]-65]==0) { sum+=d[i]; a[b[i]-65]=1; a[e[i]-65]=1; } } cout<<sum<<endl; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator