터레인 (2) 썸네일형 리스트형 [TIL]2024-2-29 / 47일차 - 심화 팀플 4일차 1.오늘의 알고리즘 코드카타 - 카드 뭉치 답안 : //복잡하게 생각해서 찾아보니 매우 간단했다. public class Solution { public string solution(string[] cards1, string[] cards2, string[] goal) { string answer = "Yes"; int index1 = 0; int index2 = 0; for(int i = 0; i < goal.Length; i++) { if(index1 < cards1.Length && goal[i] == cards1[index1]) { index1++; continue; } else if(index2 < cards2.Length && goal[i] == cards2[index2]) { index2++.. [TIL]2024-2-26 / 44일차 - 심화 팀플 시작 1.오늘의 알고리즘 코드카타 - 콜라 문제 문제 길이 이게 맞아??? 답안 : //콜라의 빈병이 소진될 때 까지니까 for문 대신 while문 //n을 a로 나누기 = 받을 횟수 이기에 n/a*b //위 계산 이후 남은 빈 병의 갯수 계산 필요 using System; public class Solution { public int solution(int a/*줘야하는 양*/, int b/*받을 양*/, int n/*남은 양*/) { int answer = 0; while(n > a - 1) // a보다 적어질 때 까지 교환 { answer += (n / a) * b; n = (n / a) * b + n % a; } return answer; } } 문제 길이는 엄청 길지만, 답안은 짧다. 국어 문제를 푸.. 이전 1 다음