标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 38192 Accepted Submission(s): 10819
#include<stdio.h> #include<math.h> #include<stdlib.h> #include<string.h> #define N 1010 int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b; } int main() { char str[N]; int a[N] = {0}; int num, flag, i; while(gets(str) != NULL){ flag = num = 0; i = 0; while(str[i] == ‘5‘){ ++i;//处理开头为5 } for(; str[i] != 0; ++i){ if(str[i] == ‘5‘ && str[i - 1] == ‘5‘) continue;//处理连续5 if(str[i] != ‘5‘) num = num * 10 + str[i] - ‘0‘; else{ a[flag++] = num; num = 0; } } if(num != 0){ a[flag++] = num; num = 0;//处理末尾5 } qsort(a, flag, sizeof(a[0]), cmp);
//输出 ,记得控制格式 for(i = 0; i < flag - 1; ++i) printf("%d ", a[i]); printf("%d\n", a[i]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/wangyuhao/p/4342829.html