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 |
求大神帮忙看一下哪里出错了?谢谢谢谢#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int a,b,n,p,sum,u; int i,j,temp,i1,j1,temp1; scanf("%d",&n); int *x; int *y; char *c; x=(int*)malloc(n*sizeof(int)); y=(int*)malloc(n*sizeof(int)); c=(char*)malloc(n*sizeof(char)); for(p=0;p<n;p++) { scanf("%d",&x[p]); scanf("%c",&c[p]); scanf("%d",&y[p]); } for(i1=0;i1<=n-1;i1++) { for(j1=0;j1<n-i1-1;j1++) { if(x[j1]>x[j1+1]) { temp1=x[j1]; x[j1]=x[j1+1]; x[j1+1]=temp1; } } } for(i1=0;i1<n;i1++) x[i1]=x[i1]-i1+1; for(i1=0;i1<=n-1;i1++) { for(j1=0;j1<n-i1-1;j1++) { if(x[j1]>x[j1+1]) { temp1=x[j1]; x[j1]=x[j1+1]; x[j1+1]=temp1; } } } if(n%2==0) a=x[n/2]+x[(n/2)+1]; else a=x[(n/2)+1]; for(i=0;i<=n-1;i++) { for(j=0;j<n-i-1;j++) { if(y[j]>y[j+1]) { temp=y[j]; y[j]=y[j+1]; y[j+1]=temp; } } } if(n%2==0) b=y[n/2]+y[(n/2)+1]; else b= y[(n/2)+1]; sum=0; for(u=0;u<n;u++) { sum=sum+abs(y[u]-b)+abs(x[u]-a); } printf("%d",sum); return 0; } 我这个方法比较笨! Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator