HDOJ HDU 1106 排序 ACM 1106 IN HDU
Posted on 2010-08-04 11:47 MiYu 閱讀(718) 評論(0) 編輯 收藏 引用 所屬分類: ACM ( 串 ) 、ACM ( 排序 ) 、ACM ( 水題 )//MiYu原創, 轉帖請注明 : 轉載自 ______________白白の屋
題目地址 :
http://acm.hdu.edu.cn/showproblem.php?pid=1106
很簡單的一道水題, 就是直接字符串拆分就行了
代碼:
題目地址 :
http://acm.hdu.edu.cn/showproblem.php?pid=1106
很簡單的一道水題, 就是直接字符串拆分就行了
代碼:
//MiYu原創, 轉帖請注明 : 轉載自 ______________白白の屋
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmp ( const void *p, const void *t )


{
return *(int *)p - *(int *)t;
}
char s[1010];
int a[1010];
int main()


{
while ( scanf("%s",s) != EOF )

{
char *t;
int n = 1;
memset ( a, 0, sizeof ( a ) );
t = strtok ( s,"5" );
a[0] = atoi ( t );
while ( t = strtok ( NULL,"5" ) )

{
a[ n ++ ] = atoi ( t );
}
qsort ( a, n, sizeof ( int ), cmp );
for ( int i = 0; i != n; ++ i )

{
printf(i ? " %d" : "%d",a[i]);
}
putchar ( '\n' );
}
return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmp ( const void *p, const void *t )

{
return *(int *)p - *(int *)t;
}
char s[1010];
int a[1010];
int main()

{
while ( scanf("%s",s) != EOF )
{
char *t;
int n = 1;
memset ( a, 0, sizeof ( a ) );
t = strtok ( s,"5" );
a[0] = atoi ( t );
while ( t = strtok ( NULL,"5" ) )
{
a[ n ++ ] = atoi ( t );
}
qsort ( a, n, sizeof ( int ), cmp );
for ( int i = 0; i != n; ++ i )
{
printf(i ? " %d" : "%d",a[i]);
}
putchar ( '\n' );
}
return 0;
}


