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 2006141329 at 2007-10-20 14:55:42 on Problem 1804
In Reply To:谁能告诉我这道题该怎做啊?TLE Posted by:8304536 at 2006-07-05 11:33:39
#include<stdio.h>
main()
{
	int sum;
	scanf("%d",&sum);
	int a[100];
	int i,j,t;
	int n;
	int count;
	int z;
	for(z=0;z<sum;z++)
	{
	  scanf("%d",&n);
	  for(i=0;i<100;i++)
	     a[i]=0;
	  for(i=0;i<n;i++)
	     scanf("%d",&a[i]);
	  count=0;
	  for(j=0;j<n;j++)
	  {
	     for(i=0;i<n-j-1;i++) 
		if(a[i]>a[i+1])
		{
				t=a[i];
				a[i]=a[i+1];
				a[i+1]=t;
				count++;
		}
	}	
	printf("Scenario #%d:\n",z+1);
	printf("%d\n",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