C#

08.C# - 알고리즘 : 순위 Rank

Godffs 2009. 8. 7. 21:13
반응형
주어진 범위 안에서 순위를 구하는 알고리즘입니다.
순위 배열을 1등으로 값을 초기화 한 후 초기값 보다 큰 값이 나오면 1씩
증가시켜서
결과값을 구하는 예제 입니다.
http://blog.naver.com/min9888596 [멍멍님 블로그]

using System;                

public class 순위
{
    public static void Main(string[] args)
    {
        //[1] Input
        int[] score = { 90, 87, 100, 95, 80, 34 };
        int[] rank = { 1, 1, 1, 1, 1, 1 };
      
        //[2] Process
        for (int i = 0; i < score.Length; i++)
        {
            for (int j = 0; j < score.Length; j++)
            {
                //비교 후 값이 작으면 1씩 증가

                if (score[i] < score[j])
                {
                    rank[i]++;
                }
            }
        }      

        //[3] Output
        for (int i = 0; i < score.Length; i++)
        {
            Console.WriteLine("{0}점 : {1}등", score[i], rank[i]);
        }
    }
}
반응형