Algorithms for calculating parallel rankings

Source: Internet
Author: User
Tags ming

Recently in a statistics, you need to calculate the student's performance rankings, but also need a side-by-side rankings, it may be said that people do not understand what is called a side-by-side rankings, for example:

Xiao Ming 100 points Small red 100 min Fang 90 points Xiao Li 80 points Xiao Sun 80 minutes Xiao Lan 70 minutes

Then the final ranking should be: Xiao Ming 1, Little Red 1, Small Fang 3, Xiao Li 4, Xiao Sun 4, Xiao Lan 6.

I believe that through the above example, we should understand what is called side-by-side sorting, the same can be tied, but different needs to calculate according to the head, words not to say, directly on the code:

  Public Static voidreckonranking () {//Here you need to rank the array according to your own ranking rules (from small to large, or from large to small) to row, you can use bubble sort or insert sorting and other algorithms, here I do not say more, Baidu go//in the following example, I'm going to write it in an orderly array.String[] Nums=Newstring[]{"100", "100", "90", "80", "80", "70", "70", "60", "60", "40"}; String Temp="";//Temp Variable        intnum=0;//Natural Sort Variables        intfinal_num=0;//Final rank variable        inttemp_num=0;//Temporary Increment         for(String str:nums) {//if the TEMP variable and the error rate are equal, the error rate is the same as the last time, but it should be the same as the last time, but to record this situation several times, and finally if the current ranking is not the same as the last time, you need to add the rank to the increment of the blank            if(Temp.equals (str)) {Temp_num++;//There are several same rank for record increments when equalFinal_num=num;//assign the rank to the same rank as the previous one}Else{num++;//rank naturally increases when not equalFinal_num=num+temp_num;//The final rank is the natural rank plus the previous equal record incrementNum=final_num;//set the natural rank to the number of final rankingstemp_num=0;//record incremental empty for equal rank} temp=STR;//use a temporary variable to record the last error rate.System.out.println ("last rank = = = =" +final_num); }    }

The above is the result of the operation, let's try to experiment it.

Algorithms for calculating parallel rankings

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.