본문 바로가기
c#/알고리즘

백준 7568 문제 덩치

by Luna_O 2020. 5. 13.

https://www.acmicpc.net/problem/7568

 

7568번: 덩치

우리는 사람의 덩치를 키와 몸무게, 이 두 개의 값으로 표현하여 그 등수를 매겨보려고 한다. 어떤 사람의 몸무게가 x kg이고 키가 y cm라면 이 사람의 덩치는 (x,y)로 표시된다. 두 사람 A 와 B의 덩�

www.acmicpc.net

처음에 풀때 x, y의 값을 따로 배열에 담아서 비교하려고 해서 코드가 꼬이고 방법이 어려움을 느낌

그래서 body 클래스를 따로 만들어 변수를 생성하고 클래스의 생성자로 값을 할당함

클래스 배열을 만들어서 키와 몸무게 값을 한번에 비교할 수 있게 함

Select를 사용하면 좀 더 간결하게 코드를 만들 수 있다해서 다시 만들어 볼 예정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _7568
{
    class Body
    {
        public int weight;
        public int height;
        public int bigger;
 
        public Body(int weight, int height)
        {
            this.weight = weight;
            this.height = height;
            this.bigger = 0;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            List<Body> list = new List<Body>();
 
            int N = int.Parse(Console.ReadLine());
            for(int i = 0; i < N; i++)
            {
                string input = Console.ReadLine();
                string[] arr = input.Split(' ');
                list.Add(new Body(int.Parse(arr[0]), int.Parse(arr[1])));
            }
 
            foreach(var body1 in list)
            {
                int x = body1.weight;
                int y = body1.height;
                foreach (var body2 in list)
                {
                    int p = body2.weight;
                    int q = body2.height;
                    if(x>&&y>q)
                    {
                        body1.bigger++;
                    }
                }
                Console.Write(body1.bigger + 1 + " ");
            }
        }
    }
}
cs

 

'c# > 알고리즘' 카테고리의 다른 글

2135 문자열 압축하기 - 어려워..나중에  (0) 2020.05.18
9996번 한국이 그리울 땐 서버에 접속하지  (0) 2020.05.17
9933 민균이의 비밀번호  (0) 2020.05.15
11654 아스키 코드  (0) 2020.05.15
백준 9498번 문제  (0) 2020.04.06