Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7509627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:58:24+00:00 2026-05-29T22:58:24+00:00

Basically I’m trying to get a rankings between 4 people. I have an array

  • 0

Basically I’m trying to get a “rankings” between 4 people. I have an array of player scores which contains the scores of each person such that person 1’s score is at index 0, person 2’s score is at index 1, etc… I want to obtain the index of the top scorer in the list and get the second, and the third, and the last.

My attempt at the solution:
I made a list out of the array playerScores (I feel like it might not be necessary, but due to what I’m about to do, I didn’t want to ruin the original scores) which contains the scores in order. And then, I find the max number in the list and get its index. Then I change the value to a negative value at that index. And then I redo the steps.

List<int> listOfScores = new List<int>(playerScores.ToList());
// We get the max value to determine the top scorer of the game
// and then we insert a negative value at that same spot of the list so we can
// continue on figuring out the following max value in the list, etc.
rank1 = listOfScores.IndexOf(listOfScores.Max());
listOfScores[rank1] = -1;

rank2 = listOfScores.IndexOf(listOfScores.Max());
listOfScores[rank2] = -1;

rank3 = listOfScores.IndexOf(listOfScores.Max());
listOfScores[rank3] = -1;

rank4 = listOfScores.IndexOf(listOfScores.Max());
listOfScores[rank4] = -1;

I feel like I can do this in a much more efficient manner and as less messy as this code…
Well, this is also assuming that negative is not a score a person can get. Is there any other way, to be more efficient than this? And what about if say we want to have negative scores?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:58:25+00:00Added an answer on May 29, 2026 at 10:58 pm

    Using LINQ:

    using System.Linq;
    
    var ranked = playerScores.Select((score, index) => 
                                     new {Player=index+1, Score=score})
                             .OrderByDescending(pair => pair.Score)
                             .ToList();
    

    And then display the winner, for example:

    Console.WriteLine(String.Format("Winner: Player {0} with score {1}", 
                      ranked[0].Player, ranked[0].Score));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I have an entity (called Session) which will provide many different Services. Each
Basically, what I'm trying to create is a page of div tags, each has
Basically, I have a JTextPane to hold some text which I wish to style.
Basically I have an IFRAME that contains a given page - I want to
Basically in my in my aspx page I have a gridview which displays the
Basically I have some sort of third party software running on Windows 7 which
Basically what I want to do it this: a pdb file contains a location
Basically I have some code to check a specific directory to see if an
Basically I am trying to restart a service from a php web page. Here
Basically, I'm trying to tap into the Soap pipeline in .NET 2.0 - I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.