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

犯了几个很水的错误,对菜鸟有帮助

Posted by Alex_Lau at 2008-04-24 19:29:10 on Problem 1007
//1007自己的垃圾代码毫无技术性可言,打算用匈牙利算法重写
#include<iostream>
using namespace std;
int main()
{
	int n,m;
	int i=0,j=0,k=0;
	long min=50000;            //min应该设定的足够大,因为字符串长度最长可达100,逆序也有可能很大
	int output=0;
	char input[1000][51]={0};  //最后找出来的错误就是这里因该是51而不是50
	int unsortness[100]={0};
	cin>>n>>m;
	for(i=0;i<m;++i)
	{
		cin>>input[i];
		for(j=0;j<n-1;++j)
			for(k=j+1;k<n;++k)
				if(input[i][j]>input[i][k])
					++unsortness[i];		
	}
	for(j=0;j<m;++j)
	{
		for(i=0;i<m;++i)
			if((unsortness[i]<min)&&(unsortness[i]>=0))    //这个判断条件一定要是unsortness[i]>=0,不能丢掉等号
			{
				min=unsortness[i];
				output=i;
			}
		cout<<input[output]<<endl;                          //自己犯了一个很水的错误,竟然写的是cout<<input[min]<<endl; 完全把下标是什么搞混
		unsortness[output]=-1;                              //这里最好设置成负数,千万不可设为0
		min=50000;                                           
	}
	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