您的位置:首页 > 其它

HDOJ1106 排序 strtok的用法

2014-02-20 09:27 375 查看
原题链接

strtok + sort就搞定了。

#include <iostream>
#include <cstring>
#include <algorithm>
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  HDOJ1106