HDOJ1106 排序 strtok的用法

原题链接

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;
}


posted on 2014-02-20 09:27  长木Qiu  阅读(138)  评论(0编辑  收藏  举报