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

AC 直接冒泡 没有那么麻烦 &%%¥¥#

Posted by 19871026 at 2009-07-30 20:34:58 on Problem 1804
#include <stdio.h>
int main()
{
	long t,n,i,j,temp,sum,count=1,a[1005];
	scanf("%d",&t);
	while (t--)
	{
		sum=0;
		scanf("%d",&n);
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		for (i=0;i<n;i++)//从后向前
		{
			for (j=n-1;j>i;j--)
			{
				if (a[j]<a[j-1])
				{
					temp=a[j];
					a[j]=a[j-1];
					a[j-1]=temp;
					sum++;
				}
			}
		}
		printf ("Scenario #%d:\n%d\n\n",count++,sum);
	}
	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