On the internet to see a small exercise, wrote one, but the time limit does not meet, and seems to have some small problems, temporarily put here, code format or something is not too standard.
1. Class ranking
Time limit: 1000ms memory limit: 65536kB
Describe
The School of Information Science and technology year-end evaluation of the fellowships, students throughout the grade according to the average score ranking.
Requirements: According to the input of the school number and the average score, according to the average grade descending output study number
If the average score is the same, output in the order entered.
Input
The first action n, which indicates the input of n students, followed by N-line input student information, 1<=n<=500
The format of student information is: School Number average score
The length of the study number is less than 10 and the average score is between 1-100.
Output
Output the school number in descending order of average score, if the average score is the same, output in the input sequence
PackageSome_demos;ImportJava.io.*;ImportJava.util.*; Public classIo_demo {//static map<integer,float> Scoreno = new treemap<integer,float> (); StaticMap<integer,float> Scoreno =NewHashmap<integer,float>(); StaticList<float> score =NewArraylist<float>(); StaticList<integer> No =NewArraylist<integer>(); Public Static voidSortlist (list<float> flist, list<integer>IList) { intLength =flist.size (); if(Length <= 0) return; for(inti=0; i<length; i++){ for(intj=i+1;j<length;j++){ floatITemp =Flist.get (i); floatJtemp =Flist.get (j); floatfloattemp; intILISTTEMP1 =Ilist.get (i); intJLISTTEMP2 =Ilist.get (j); intintTemp; if(itemp<jtemp) {Floattemp=iTemp; Flist.set (i, jtemp); Flist.set (J, Floattemp); //intTemp = ILISTTEMP1;Ilist.set (i, JLISTTEMP2); Ilist.set (J, ILISTTEMP1); } } } } Public Static voidMain (string[] args) {LongStartTime =System.nanotime (); Try{bufferedreader br=NewBufferedReader (NewInputStreamReader (system.in)); String strtemp=Br.readline (); String[] Strarray; while(strtemp!=NULL){ //System.out.println (strtemp); if(Strtemp.equals ("Bye")) Break; Strarray= Strtemp.split (""); //System.out.println (Strarray[0] + "-" + strarray[1]);Scoreno.put (Integer.parseint (strarray[0]), Float.parsefloat (strarray[1])); Score.add (Float.parsefloat (strarray[1])); No.add (Integer.parseint (strarray[0])); strtemp=Br.readline (); } System.out.println (Scoreno); SYSTEM.OUT.PRINTLN (score); Sortlist (Score,no); SYSTEM.OUT.PRINTLN (score); System.out.println (no); }Catch(IOException e) {System.out.println (e); }Catch(Exception e) {System.out.println (e); } LongEndTime =System.nanotime (); System.out.println ("Program execution Common:" + ((endtime-starttime)/1000000) + "MS"); }}
2, hexadecimal to decimal
Time limit: 1000ms memory limit: 65536kB
Describe
Converts a hexadecimal number to a decimal number
Input
The first line has an integer t, which indicates a total T-group data
Next T line, each behavior a 16 binary unsigned positive integer, the number of digits not more than 8 bits, the number of a-f are uppercase letters, the number of the previous no extra 0
Output
Outputs a total of T-lines, each of which is a decimal representation of a set of data, with no additional 0 before the number.
Decimal number less than 2^31
PackageSome_demos;ImportJava.io.*; Public classHextobin {//Public void Hextobin (int[] array) {//int length = Array.Length;//for (int j=0; j<length; J + +) {// // }// }// Public Static voidMain (string[] args) {LongStartTime =System.nanotime (); Try{bufferedreader br=NewBufferedReader (NewInputStreamReader (system.in)); String Strnum=Br.readline (); intCount =Integer.parseint (Strnum); if(Count <= 0) {System.out.println ("The number of inputs should be greater than 0!" "); return; } int[] hex =New int[Count]; String strtemp; for(inti=0; i<count; i++) {strtemp=Br.readline (); Hex[i]= Integer.valueof (strtemp, 16); //System.out.println (integer.valueof (strtemp,16)); } //Hextobin (hex); //System.out.println (hex); for(intj=0; j<count; J + +) System.out.println (Hex[j]); }Catch(NumberFormatException e) {System.out.println (e); }Catch(IOException e) {System.out.println (e); }Catch(Exception e) {System.out.println (e); } LongEndTime =System.nanotime (); System.out.println ("Program execution Common:" + ((endtime-starttime)/1000000) + "MS"); }}
Two Java little exercises