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 scuttemp at 2009-01-10 11:13:49 on Problem 1007
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

typedef struct { string str  ; int unorder ; } item;

void init( int n , vector<item> & dna)
{
	for ( int i = 0 ; i < n ; ++ i )
		dna[i].unorder = 0 ;
}

void calcu ( int n , int m , vector<item> & dna)
{
	for ( int i = 0 ; i < m ; ++ i )
		for ( int j = 0 ; j < n ; ++ j )
			for ( int k = j ; k < n ; ++ k )
				if ( dna[i].str[j] > dna[i].str[k] )
					dna[i].unorder ++ ;
}

bool operator< ( item & lhs , item & rhs )
{
	return  ( lhs.unorder < rhs.unorder ) ;
}

int main()
{
	int n , m ;
	cin >>	n >> m;

	vector<item> dna;
	item in ;

	for ( int i = 0 ; i < m ; ++ i )
	{
		cin >> in.str ;
		dna.push_back ( in );
	}

	init( m , dna );
	calcu( m , n , dna);

	//写个排序玩玩

	item temp;

	for ( int i = 1 ; i < m ; ++ i )
	{
		temp = dna[i];
		int j ;
		for ( j = i ; j >= 0 ; -- j )
		{
			if ( dna[j] < dna[ j -1 ] )
			{
				dna[j] = dna[j-1];
			}
			else break;
		}
		dna[j] =temp ;
	}

	///一直到这里
	for ( int i = 0 ; i < m ; ++ i ) 
		cout << dna[i].str << endl;
	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