排序
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 48472 Accepted Submission(s): 13987
Problem Description
输入一行数字,如果我们把这行数字中的‘5’都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以‘0’开头,这些头部的‘0’应该被忽略掉,除非这个整数就是由若干个‘0’组成的,这时这个整数就是0)。
你的任务是:对这些分割得到的整数,依从小到大的顺序排序输出。
Input
输入包含多组测试用例,每组输入数据只有一行数字(数字之间没有空格),这行数字的长度不大于1000。
输入数据保证:分割得到的非负整数不会大于100000000;输入数据不可能全由‘5’组成。
Output
对于每个测试用例,输出分割得到的整数排序的结果,相邻的两个整数之间用一个空格分开,每组输出占一行。
Sample Input
0051231232050775
Sample Output
0 77 12312320
Source
POJ
题解:使用atoi()函数和strtok()函数搞定。。。。
strtok函数解析:
Syntax:
#include < string.h>
char *strtok( char *str1, const char *str2 );
The strtok() function returns a pointer to the next “token” in str1, where str2 contains the delimiters that determine the token. strtok() returns NULL if no token is found. In order to convert a string to tokens, the first call to strtok() should have str1 point to the string to be tokenized. All calls after this should have str1 be NULL.
For example:
char str[] = “now # is the time for all # good men to come to the # aid of their country”;
char delims[] = “#”;
char *result = NULL;
result = strtok( str, delims );
while( result != NULL ) {
printf( “result is \”%s\”\n”, result );
result = strtok( NULL, delims );
}
The above code will display the following output:
result is “now ”
result is ” is the time for all ”
result is ” good men to come to the ”
result is ” aid of their country”
AC代码:
orAC2代码: