일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- convert
- git
- Coding
- 코딩테스트
- Github
- log
- mysql
- Visual Studio
- chashtag
- Binding
- windows10
- logging
- Microsoft
- tls
- nullable
- csharp
- coding-test
- IValueConverter
- Process
- File
- algorithm
- WPF
- commit
- .net
- programmers
- ListView
- dotNET
- windows
- string
- C#
Archives
- Today
- Total
CHashtag
[프로그래머스] [C#] 상호평가 본문
반응형
안녕하세요.
오늘은 프로그래머스 코딩테스트 연습 문제인 "부족한 금액 계산하기" 을 풀어보았습니다.
문제 링크
https://programmers.co.kr/learn/courses/30/lessons/83201
코딩테스트 연습 - 2주차_상호평가
[[100,90,98,88,65],[50,45,99,85,77],[47,88,95,80,67],[61,57,100,80,65],[24,90,94,75,65]] "FBABD" [[70,49,90],[68,50,38],[73,31,100]] "CFD"
programmers.co.kr
문제 풀이 방법
이번 문제의 풀이는 주석으로 달아두었습니다.
또한 이번 문제는 평균 약 0.37ms 정도의 속도로 테스트를 통과하였습니다.
public string solution(int[,] scores)
{
string answer = string.Empty;
// n*n 배열이므로 index는 하나만 구하면 된다.
int index = scores.GetLength(0);
for (int i = 0; i < index; i++)
{
int largest = -1;
int largestCount = 0;
int smallest = 101;
int samllestCount = 0;
int totalScore = 0;
for (int j = 0; j < index; j++)
{
totalScore += scores[j, i];
if (scores[j, i] > largest)
{
largest = scores[j, i];
largestCount = 1;
}
else if (scores[j, i] == largest)
{
largestCount++;
}
else if (scores[j, i] < smallest)
{
smallest = scores[j, i];
samllestCount = 1;
}
else if (scores[j, i] == smallest)
{
samllestCount++;
}
}
int totalScoreAvg;
// 유일한 최고점
if (largest == scores[i, i] && largestCount == 1)
{
totalScore -= largest;
totalScoreAvg = totalScore / (index - 1);
}
// 유일한 최저점
else if (smallest == scores[i, i] && samllestCount == 1)
{
totalScore -= smallest;
totalScoreAvg = totalScore / (index - 1);
}
else
{
totalScoreAvg = totalScore / index;
}
// switch-case 문을 사용하기 위해 10으로 나누어줌.
totalScoreAvg /= 10;
switch (totalScoreAvg)
{
case 10:
case 9:
answer += "A";
break;
case 8:
answer += "B";
break;
case 7:
answer += "C";
break;
case 6:
case 5:
answer += "D";
break;
default:
answer += "F";
break;
}
}
return answer;
}
감사합니다.
반응형
'알고리즘' 카테고리의 다른 글
[프로그래머스] [Java] 없는 숫자 더하기 (0) | 2021.09.14 |
---|---|
[프로그래머스] [C#] 없는 숫자 더하기 (0) | 2021.09.14 |
[프로그래머스] [Java] 부족한 금액 계산하기 (2) | 2021.08.02 |
[프로그래머스] [C#] 부족한 금액 계산하기 (0) | 2021.08.02 |
[프로그래머스] [C#] 숫자 문자열과 영단어 (0) | 2021.08.02 |