HDOJ1106 排序 strtok的用法

2014-11-24 09:20:52 · 作者: · 浏览: 0

原题链接

strtok + sort就搞定了。

#include 
  
   
#include 
   
     #include 
    
      using namespace std; #define MAX 1000 + 2 char str[MAX]; int a[MAX]; int main(){ int count; char *p; while(scanf("%s", str) == 1){ count = 0; p = strtok(str, "5"); while(p != NULL){ sscanf(p, "%d", &a[count++]); p = strtok(NULL, "5"); } sort(a, a + count); int flag = 0; for(int i = 0; i != count; ++i) if(!flag) printf("%d", a[i]), flag = 1; else printf(" %d", a[i]); putchar('\n'); } return 0; }