코딩테스트 24

[프로그래머스] 다리를 지나는 트럭 | C#

[ 다리를 지나는 트럭 ] 문제 설명 트럭 여러 대가 강을 가로지르는 일차선 다리를 정해진 순으로 건너려 합니다. 모든 트럭이 다리를 건너려면 최소 몇 초가 걸리는지 알아내야 합니다. 다리에는 트럭이 최대 bridge_length대 올라갈 수 있으며, 다리는 weight 이하까지의 무게를 견딜 수 있습니다. 단, 다리에 완전히 오르지 않은 트럭의 무게는 무시합니다. 예를 들어,트럭 2대가 올라갈 수 있고 무게를 10kg까지 견디는 다리가 있습니다. 무게가 [7, 4, 5, 6]kg인 트럭이 순서대로 최단 시간 안에 다리를 거너려면 다음과 같이 건너야 합니다. 경과 시간 다리를 지난 트럭 다리를 건너는 트럭 대기 트럭 0 [] [] [7, 4, 5, 6] 1 ~ 2 [] [7] [4, 5, 6] 3 [7]..

[프로그래머스] 달리기 경주 | C#

[ 달리기 경주 ] 문제 설명 얀에서는 매년 달리기 경주가 열립니다. 해설진들은 선수들이 자기 바로 앞의 선수를 추월할 때 추월한 선수의 이름을 부릅니다. 예를 들어 1등부터 3등까지 "mumu", "soe", "poe" 선수들이 순서대로 달리고 있을 때, 해설진이 "soe"선수를 불렀다면 2등인 "soe" 선수가 1등인 "mumu" 선수를 추월했다는 것입니다. 즉 "soe" 선수가 1등, "mumu" 선수가 2등으로 바뀝니다. 선수들의 이름이 1등부터 현재 등수 순서대로 담긴 문자열 배열 players와 해설진이 부른 이름을 담은 문자열 배열 callings가 매개변수로 주어질 때, 경주가 끝났을 때 선수들의 이름을 1등부터 등수 순서대로 배열에 담아 return 하는 solution 함수를 완성해주세..

[백준 코딩테스트] 2739번, 10950번 | C#, Python, C

[ 2739번 ] [ C# ] int num = int.Parse(Console.ReadLine()); for(int i = 1; i < 10; i++) Console.WriteLine(num + " * " + i + " = " + num * i); [ Python ] num = int(input()) for i in range(1, 10): print(str(num) + " * " + str(i) + " = " + str((num) * i)) 파이썬은 문자열과 숫자를 같이 출력하려면 숫자를 문자열로 변환해야 한다. [ C ] #include int main(){ int num; scanf("%d", &num); for(int i = 1; i < 10; i++) { printf("%d * %d = %d\..

[백준 코딩테스트] 2480번 | C, C#, Python

[ 2480번 ] [ C# ] string[] ss = Console.ReadLine().Split(); int a = int.Parse(ss[0]); int b = int.Parse(ss[1]); int c = int.Parse(ss[2]); int win; if(a == b || a == c){ if(b == c) win = 10000+a*1000; else win = 1000+a*100; } else if(b == c){ if(a == b) win = 10000 +b* 1000; else win = 1000+b*100; } else { if (a > b && a > c) win = a * 100; else if(b>a&& b> c) win = b *100; else win = c * 100; } C..

[백준 코딩테스트] 2884번, 2525번 | C, C#, Python

[ 2884번 ] [ C# ] string[] s = Console.ReadLine().Split(); int h = int.Parse(s[0]); int m = int.Parse(s[1]); m -= 45; if(m < 0){ m += 60; h -= 1; if(h < 0) h = 23; } Console.WriteLine($"{h} {m}"); [ Python ] h, m = map(int, input().split()) m -= 45 if(m < 0): m += 60 h -= 1 if(h < 0): h = 23 print("{} {}".format(h, m)) [ C ] #include int main(){ int h, m; scanf("%d %d", &h, &m); m -= 45; if(m < 0..

[백준 코딩테스트] 2753번, 14681번 | C, C#, Python

[ 2753번 | 윤년 ] https://www.acmicpc.net/problem/2753 [ C# ] int y = int.Parse(Console.ReadLine()); if(y % 400 == 0) Console.Write(1); else if(y % 100 == 0) Console.Write(0); else if(y % 4 == 0) Console.Write(1); else Console.Write(0); [ Python ] y = int(input()) if(y % 400 == 0): print(1) elif(y % 100 == 0): print(0) elif(y % 4 == 0): print(1) else: print(0) [ C ] #include int main(){ int y; scan..

[백준 코딩테스트] 11382번, 10171번, 10172번 | C#, Python

[ 11382번 ] https://www.acmicpc.net/problem/11382 11382번: 꼬마 정민 첫 번째 줄에 A, B, C (1 ≤ A, B, C ≤ 1012)이 공백을 사이에 두고 주어진다. www.acmicpc.net [ C# ] string[] s = Console.ReadLine().Split(); long[] nums = new long[3]; long total = 0; for(int i = 0; i < 3; i++){ nums[i] = long.Parse(s[i]); total += nums[i]; } Console.Write(total); [ Python ] s = list(map(int, input().split())) total = 0 for i in range(3):..

[백준 코딩테스트] 10430번, 2588번 | C#, Python

[ 10430번 ] https://www.acmicpc.net/problem/10430 10430번: 나머지 첫째 줄에 A, B, C가 순서대로 주어진다. (2 ≤ A, B, C ≤ 10000) www.acmicpc.net [ C# ] string s = Console.ReadLine(); string[] ss = s.Split(); int a = int.Parse(ss[0]); int b = int.Parse(ss[1]); int c = int.Parse(ss[2]); Console.WriteLine((a+b)%c); Console.WriteLine(((a%c)+(b%c))%c); Console.WriteLine((a*b)%c); Console.WriteLine(((a%c) * (b%c)) % c); ..