0 of 1 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 1 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
阅读程序写出结果:(2014年提高组)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#include <stdio.h> #include <string.h> const int SIZE = 100; const int LENGTH = 25; /* * strcmp(a,b) <0:a的字典序小于b * strcmp(a,b) =0:a和b一样 * strcmp(a,b) >0:a的字典序大于b */ int main() { char dict[SIZE][LENGTH + 1]; int rank[SIZE]; int ind[SIZE]; int i, j, n, tmp; scanf( "%d", &n ); for ( i = 1; i <= n; i++ ) { rank [i] = i; ind[i] = i; scanf( "%s", dict[i] ); } for ( i = 1; i < n; i++ ) for ( j = 1; j <= n - i; j++ ) if ( strcmp( dict[ind[j]], dict[ind[j + 1]] ) > 0 ) { tmp = ind[j]; ind[j] = ind[j + 1]; ind[j + 1] = tmp; } for ( i = 1; i <= n; i++ ) rank[ind[i]] = i; for ( i = 1; i <= n; i++ ) printf( "%d ", rank[i] ); printf( "\n" ); return(0); } |
输入:
7
aaa
aba
bbb
aaa
aaa
ccc
aa
输出: