Topic 1110: Little white Rat line
Topic Description:
N Mice (1 <= n <= 100) with a colored hat on each mouse head. The weight of each mouse is now called, requiring that the color of the hat on the head be printed in the order of the weight of the mouse. The color of the hat is represented by a string such as "Red" and "blue". Different mice can wear hats of the same color. The weight of the white mouse is expressed in integers.
Input:
Multiple case input, each case input first act an integer n, representing the number of mice.
There are n rows below, and each row is the information of a white mouse. The first is a positive integer that is not greater than 100, indicating the weight of the mouse, and the second is a string representing the color of the hat of the white mouse and the string length of no more than 10 characters.
Note: The weight of the mouse is different.
Output:
Each case prints the color of the mouse's hat in the order of the mouse's weight from large to small.
Sample input:
3
Red
Blue
Green
Sample output:
Blue
Green
Red
Source:
2007 Peking University computer Research Life Test real problem code
C Language Implementation
#include <stdio.h> int main () { int a[101],b[101],
N,i,j,temp;
char c[101][12]; while (scanf ("%d", &n) = = 1) { if (n<1 | |
N>100) continue; else { for (i=1;i<=n;i++) {
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%d%s", A+i,c[i]);
b[i]=a[i]; } for (i=1;i<n;i++) for (j=1;j<=N-i;j++) if (A[j]>a[j+1]) {
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
&NBSP;&NBSP} for (i=N;i>=1;i--) &nbSp; for (j=1;j<=n;j++) if (B[j]==a[i]) printf (" %s\n ", C[j]); } }
return 0; }/************************************************************** problem:1110
user:langzimaizan language:c result:accepted time:0 Ms memory:912 KB ****************************************** **********************/