Nine degree Online Judge algorithm brush title 1110: White Mouse queue __ algorithm

Source: Internet
Author: User
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&GT;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 ****************************************** **********************/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.