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 |
Tags
- 백준 17070번
- 백준
- 백준 c++ 2870번
- Unity
- Lv2
- 코딩테스트
- 백준 1103번 c++
- dfs
- 플레이어 이동
- 2870번 c++
- 백준 17070번 c++
- 코테
- 백준 2870번
- 백준 1103번 게임
- Algorithm
- 2870번 수학숙제 c++
- 백준 c++ 2468번
- 17070번
- Beakjoon
- 오브젝트 풀링
- C#
- 유니티
- 수학숙제
- 프로그래머스
- 2468 c++
- 2870번 수학숙제
- c++
- 2870번
- Lv.3
- 백준 1103번
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.2 할인 행사 본문
https://school.programmers.co.kr/learn/courses/30/lessons/131127
1. 정답코드 및 핵심 아이디어, 유의사항
원하는 제품을 모두 할인상품으로 구매할 수 있는 날의 숫자를 구하는 문제
- 원하는 제품들의 개수의 총합과 연속으로 일치해야 하는 날짜의 수가 같으므로, 모든 제품을 10일의 기간동안 원하는 개수만큼 딱 맞게 구매해야 함
- Dictionary<key, value> 활용 ( key : 원하는 제품, value : 원하는 제품 수량 )
https://godgjwnsgur7.tistory.com/46
주석참조
using System;
using System.Collections.Generic;
public class Solution
{
public int solution(string[] want, int[] number, string[] discount)
{
int answer = 0;
// 과일이름 want, 과일 수 number를 담을 딕셔너리
Dictionary<string, int> dict = new Dictionary<string, int>();
// 0번 인덱스부터 10개씩 확인
for (int i = 0; i < discount.Length - 9; i++)
{
// 딕셔너리 값 초기화
for (int j = 0; j < want.Length; j++)
dict.Add(want[j], number[j]);
// 원하는 과일 구매
for (int j = i; j < i + 10; j++)
if (dict.ContainsKey(discount[j]))
dict[discount[j]]--;
// 원하는 모든 과일을 다 구매헀는지 판단
int maxValue = 0;
foreach (int dictValue in dict.Values)
if (dictValue > maxValue)
maxValue = dictValue;
// 원하는 모든 과일을 구매했다면 10일 연속 일치
if (maxValue == 0)
answer++;
dict.Clear();
}
return answer;
}
}
'CodingTest > Programmers Lv.2' 카테고리의 다른 글
[프로그래머스 C#] Lv.2 다리를 지나는 트럭 (0) | 2023.11.14 |
---|---|
[프로그래머스 C#] Lv.2 두 큐 합 같게 만들기 (0) | 2023.11.13 |
[프로그래머스 C#] Lv.2 요격 시스템 (0) | 2023.11.09 |
[프로그래머스 C#] Lv.2 두 원 사이의 정수 쌍 (0) | 2023.11.07 |
[프로그래머스 C#] Lv.2 행렬 테두리 회전하기 (2) | 2023.11.03 |