#include
<stdio.h> #include
<string.h> #define
N 150 void
s( char
x[N][20], int
n); main() { char
x[N][20]; int
n; printf ( "How
many countries?" ); scanf ( "%d" ,
&n); printf ( "Input
their names:\n" ); int
i; for
(i = 0; i < n; i++) { scanf ( "%s" ,
x[i]); } s(x,
n); printf ( "Sorted
results:\n" ); for
(i = 0; i < n; i++) { puts (x[i]); } } void
s( char
x[N][20], int
n) { int
j, k; char
temp[20]; for
(k = 0; k < n - 1; k++) { for
(j = k + 1; j < n; j++) { if
( strcmp (x[j],
x[k]) < 0) { strcpy (temp,
x[k]); strcpy (x[k],
x[j]); strcpy (x[j],
temp); } } } } |
字符排序
最新推荐文章于 2024-04-06 22:37:15 发布