C# 알고리즘 코딩(프로그래머스)(36)
-
프로그래머스 C# 피자 나누어 먹기(3) (파이썬, 자바)
using System; public class Solution { public int solution(int slice, int n) { int answer = 0; while (n/slice > answer) { answer++; } //나눠지는 경우에는 answer를 증가시켜서 바로 출력 12/4 = 3 //나눠지지 않아도 answer를 증가시켜서 while문에서 빠져 나올 때가 피자의 판 수-1가 되게 한다. if(n%slice != 0) { answer++; } // 나머지가 있을 때 피자의 판 수를 +1시켜야 answer가 제대로 출력된다. return answer; } } //인트형으로만 되어 있어서 나머지가 있을 때랑 0일 때의 경우를 if문으로 넣어서 했다. 파이썬 def solution..
2023.04.16 -
프로그래머스 C# 직각삼각형 출력하기(파이썬, 자바)
using System; public class Example { public static void Main() { String[] s; Console.Clear(); s = Console.ReadLine().Split(' '); int n = Int32.Parse(s[0]); for (int i = 1; i
2023.04.15 -
프로그래머스 C# 배열 뒤집기(파이썬, 자바)
using System; public class Solution { public int[] solution(int[] num_list) { int[] answer = new int[num_list.Length]; int i = 0; for(i=num_list.Length-1;i>=0;i--) { answer[num_list.Length-i-1] = num_list[i]; } return answer; } } for문으로 맨 마지막 부터 집어 넣기 using System; public class Solution { public int[] solution(int[] num_list) { int[] answer = new int[num_list.Length]; int K =0; for(int i = num_l..
2023.04.14 -
프로그래머스 C# 머쓱이보다 키 큰 사람
using System; public class Solution { public int solution(int[] array, int height) { int answer = 0; for(int i=0;i height) { answer++; } } return answer; } } 파이썬 ///// def solution(array, height): return sum(1 for a in array if a > height) /////// def solution(array, height): array.append(height) array.sort(reverse=True) return array.index(height) 자바 class Solution { public int solution(int[] ar..
2023.04.11 -
프로그래머스 C# 배열 안에 있는 수를 2배씩 하기
using System; public class Solution { public int[] solution(int[] numbers) { int[] answer = new int[numbers.Length]; for(int i=0;i
2023.04.10 -
프로그래머스 C# 양꼬치(파이썬, 자바)
using System; public class Solution { public int solution(int n, int k) { if(n 0 && k >= n/10 && k
2023.04.09