题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1106
这个题目一开始以为是水题,就想着用来轻松轻松,谁知道改得我想吐!!
除了discuss 中的数据外,还加上这两组,一般就能过了:001568970056 5551235555789
1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 const int maxn = 1000 + 10; 7 char s[maxn], t[maxn]; 8 int a[maxn]; 9 10 int main() 11 { 12 int i, l, f, tl, tmp, len; 13 while (gets(s)) 14 { 15 len = strlen(s); 16 tmp = tl = l = 0; 17 for (i = 0; i < len; i++) 18 { 19 f = 0; 20 while (s[i] == '5' && i < len) // 过滤5 21 { 22 i++; 23 f = 1; 24 } 25 if (f) 26 i--; 27 while (s[i] != '5' && i < len) 28 t[tl++] = s[i++]; 29 if (i == len) // 最后无5结束 30 { 31 t[tl] = '\0'; 32 sscanf(t, "%d", &tmp); 33 a[l++] = tmp; 34 break; 35 } 36 if (s[i] == '5' && s[i-1] != '5' && i != 0) // 排除一连串的5和以5开头 37 { 38 t[tl] = '\0'; 39 sscanf(t, "%d", &tmp); 40 a[l++] = tmp; 41 tl = 0; 42 } 43 } 44 sort(a, a+l); 45 for (i = 0; i < l-1; i++) 46 printf("%d ", a[i]); 47 printf("%d\n", a[i]); 48 } 49 return 0; 50 }