HDU1106

1313 단어 HDU
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
", sort[i]); } return 0; }

좋은 웹페이지 즐겨찾기