Topic 1110: White mouse queue Java

Source: Internet
Author: User

Title Description:

N Mice (1 <= N <= 100), each with a colored hat on its head. The weight of each white mouse is now weighed, requiring the color of the hats to be output in the order in which the rats ' weights are from large to small. The color of the hat is represented by a string such as "Red", "blue". Different mice can wear hats of the same color. The weight of the mouse is expressed in integers.

Input:
multiple case inputs, input of each case an integer n, representing the number of mice. There are n rows, each of which is a white mouse message. The first is a positive integer not greater than 100, which represents the weight of the mouse, and the second is a string representing the color of the white mouse's hat, and the string length is no more than 10 characters. Note: The weight of the mice is different.
Output:

Each case output The white mouse's hat color in the order of the mouse's weight from large to small.

Sample input:
RED50 Blue40 Green
Sample output:
Bluegreenred


I wrote this, and it turned out to be pw!. I can't find the reason why! Also hope that AC Daniel can answer the answer!


Import Java.util.Scanner;    Class m{int mouse_weight[]=new int[1000];    Char Mouse_color[][]=new char[1000][1000]; String[] mouse_color=new string[1000];}      public class main{public static void Main (String args[]) {Scanner cin =new Scanner (system.in);          while (Cin.hasnext ()) {int mouse_num=cin.nextint ();          M m=new m ();          mouse int i,j,k = 0;          int tempweight;          String Tempcolor;   for (i=0;i<mouse_num;i++) {m.mouse_weight[i]=cin.nextint ();             Take the weight and color of the mouse separately//m.mouse_color[i]=cin.nextline ();             M. Mouse_color[i]=cin.nextline ();          System.out.println (m.mouse_color[i]+ "" +m.mouse_weight[i]); } for (j=0;j<i;j++) {for (k=0;k<i;k++) {if (M.mouse_weig Ht[k]<m.mouse_weight[k+1]) {Tempweight=m.mouse_weight[k];m.mouse_weight[k]=m.mou Se_weight[k+1];m.mOuse_weight[k+1]=tempweight;                  Tempcolor=m.mouse_color[k];m.mouse_color[k]=m.mouse_color[k+1];m.mouse_color[k+1]=tempcolor;              }}} for (i=0;i<k;i++) {System.out.print (m.mouse_color[i]);          System.out.print ("\ n");      }//system.out.print ("\ n");    }}}/************************************************************** problem:1110 User:carvin Language:java Result:presentation error****************************************************************/


Import Java.util.arrays;import Java.util.scanner;class Mous implements comparable<mous>{int num;    String color;        @Override public int CompareTo (Mous i) {if (this.num>i.num) {return-1;        }else{return 1;    }}}public class main{static Mous mous[];    Static Mous MoU;        public static void Main (string[] args) {Scanner in = new Scanner (system.in);            while (In.hasnext ()) {int n = in.nextint ();            mous = new Mous[n];                for (int i=0;i<n;i++) {mou = new Mous ();                Mou.num=in.nextint ();                Mou.color=in.next ();            Mous[i]=mou;            } arrays.sort (MOUS);            for (int i=0;i<n;i++) {System.out.println (mous[i].color);    }}}}/************************************************************** problem:1110 User:carvin Language:java Result:accepted time:120 Ms memory:18852 kb****************************************************************/ 



Topic 1110: White mouse queue Java

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.