Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 랜덤
- 전면광고
- UGUI
- LINQ
- dotween
- 모션
- csvhelper
- C#
- 광고테스트
- 컴퓨터구조
- unity
- ui
- 유니티
- 유니티기초
- enum
- unity3D
- 애드몹
- 유니티기본
- 열거형
- Admob
- React Native
- scrollrect
- 게임개발
- 애니메이션
- unity통신
- cs
- canvasgroup
- 코딩테스트
- 프로그래머스
- http
Archives
- Today
- Total
Ruya Games
[프로그래머스] (C#) 코딩테스트 연습 - 과일 장수 본문
using System;
using System.Linq;
public class Solution {
public int solution(int k, int m, int[] score) {
var boxCount = score.Length / m;
var orderedScore = score.OrderByDescending(x => x).ToList();
int sum = 0;
for(int i = 0; i < boxCount; i++) {
int a = orderedScore.Skip(m*i).Take(m).Min();
int b = a * m;
sum += b;
}
return sum;
}
}
단순히 점수의 배열을 내림차순 또는 오름차순으로 정렬한 후, m개씩 Take하면서 곱해주면서 더해주면 되는 간단한 문제입니다.
사실 Linq안쓰고 System.Array의 Array 클래스들을 쓰면 됩니다...
https://learn.microsoft.com/ko-kr/dotnet/api/system.array?view=net-8.0&redirectedfrom=MSDN
'코딩테스트' 카테고리의 다른 글
[프로그래머스] (C#) 공원 산책 (1) | 2024.06.04 |
---|