View Code of Problem 17

#include <stdio.h>
int a[1000];
void paixu(int len)
{
	int i,j,key;
	for (j=1;j<len;j++)
		{
			key = a[j];
			i=j-1;
			while (a[i]>key&&i>=0)
			{
				a[i+1]=a[i];
				i--;
			}
			a[i+1]=key;
		}
}
int main()
{
	int m,n,i,j=0,b;
	while(scanf("%d %d",&m,&n)!=EOF)
	{
		for (i=0;i<m*n;i++)
			scanf("%d",&a[i]);
		paixu(m*n);
		for(i=1,b=a[0],j=0;i<m*n;i++)
		{
			if (a[i]>b)
			{
				j++;
				b=a[i];
			}
		}
	printf("%d\n",j);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 17