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

为何temp[100][50]改成temp[100][51]就行了呢,

Posted by ekoi at 2008-08-07 12:32:06 on Problem 1007
我的代码,
#include<iostream>
using namespace std;

char temp[100][51];//为temp[100][50]就RE了
int b[100];
int work(int n,char t[50]);
int main()
{
	freopen("in.txt","r",stdin);
	char tt[50];
	int n,m,i,j,t;
	cin>>n>>m;
	for( i=0; i<m; i++)
	{
		cin>>temp[i];
		b[i]=work(n,temp[i]);
	}

	
	for( i=0; i<m-1; i++)
		for( j=i+1; j<m; j++)
		{
			if(b[i]>b[j])
			{
				t=b[i];
				b[i]=b[j];
				b[j]=t;
				strcpy(tt,temp[i]);
				strcpy(temp[i],temp[j]);
				strcpy(temp[j],tt);
			}

		}

		for( i=0; i<m; i++)
			cout<<temp[i]<<endl;







	return 0;
}

int work(int n,char t[50])//n为当前串的长度
{
	int i,j,l,count(0);
	l=strlen(t);
	for( i=0; i<l-1; i++)
		for( j=i+1; j<l; j++)
			if( t[i]>t[j])
				count++;

	return count;
}



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