HDU1106

http://acm.hdu.edu.cn/showproblem.php?pid=1106
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXN 1005

char Number[MAXN];
long sort[MAXN];

int cmp(const void *a, const void *b)
{
	return *(long *)a - *(long *)b;
}
//注意问题:
//1.5开头的不能输出0
//2.中间存在多个5时,只要一个5忽略其他5 11555512
int main()
{
	int i, num, j;
	while(scanf("%s", Number) != EOF)
	{
		int len = strlen(Number);
		num = 0;
		j = 0;
		for(i = 0; i <= len; i++)
		{
			if(i == 0 && Number[i] == '5')
				continue;
			if(Number[i] == '5' || i == len)
			{
				sort[j++] = num;
				if((i == len && num == 0) || Number[i - 1] == '5')
					j--;
				num = 0;
			}else
			{
				num = num * 10 + Number[i] - '0';
			}
		}
		qsort(sort, j, sizeof(long), cmp);
		for(i = 0; i < j - 1; i++)
		{
			printf("%ld ", sort[i]);
		}
		printf("%ld\n", sort[i]);
	}
	return 0;
}

你可能感兴趣的:(HDU)