Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

晕,一直是WA,哪位高人帮忙看看!

Posted by xienanjie at 2010-11-19 15:27:05 on Problem 1007 and last updated at 2010-11-19 15:38:46
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator