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<conio.h> int inversion(char str[][500],int n,int k){ int i,j,count=0; char temp,strl[500]; for(i=0;i<n;i++) strl[i]=str[k][i]; for(i=0;i<n;i++){ for(j=0;j<n-i-1;j++){ if(strl[j]>strl[j+1]){ temp=strl[j]; strl[j]=strl[j+1]; strl[j+1]=temp; ++count; } } } return count; } int main(void) { char str[1000][500]; int m,n,i,j,count[100],min=1000000,min2,t,k,temp; while(scanf("%d%d",&n,&m)!=EOF){ for(i=0;i<m;i++){ scanf("%s",&str[i]); } for(i=0;i<m;i++){ count[i]=inversion(str,n,i); } for(i=0;i<m;i++){ if(min>count[i]){ min=count[i]; t=i; } } for(i=0;i<m;i++){ temp=t; min2=100; printf("%s\n",str[t]); for(j=0;j<m;j++){ if(count[j]==min&&(j!=t)&&(j!=temp)){ t=j; printf("%s\n",str[t]); ++i; } } for(j=0;j<m;j++){ if(min2>count[j]&&count[j]>min){ min2=count[j]; t=j; } } min=min2; } } //getch(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator