Algorithms (15) 썸네일형 리스트형 Programers-7_행렬의 덧셈 내 코드: public class Solution { public int[,] solution(int[,] arr1, int[,] arr2) { int[,] answer = new int[arr1.GetLength(0), arr1.GetLength(1)]; for(int i = 0; i < answer.GetLength(0); i++){ for(int j = 0; j < answer.GetLength(1); j++){ answer[i,j] = arr1[i,j] + arr2[i,j]; } } return answer; } } Programers - 6 _ 콜라츠 추측 public class Solution { public int solution(int num) { int answer = 0; for (int i = 0; i < 500; i++) { if(num % 2 == 0) { num = IfEven(num); } else if(num % 2 == 1) { num = IfOdd(num); } if(num == 1) { answer = i; return answer; } } return -1; } public int IfOdd(int num) { num = (num * 3) + 1; return num; } public int IfEven(int num) { num = num / 2; return num; } } Programers - 5 _ 평균 구하기 public class Solution { public double solution(int[] arr) { double answer = 0; double total = 0; for(int i = 0; i < arr.Length; i++) { total += arr[i]; } answer = total / arr.Length; return answer; } } Programers - 4 _ 하샤드 수 내 풀이: public class Solution { public bool solution(int x) { int a = 0; string b = x.ToString(); bool answer = true; for(int i = 0; i < b.Length; i++) { a += int.Parse(b.Substring(i,1)); } if (x % a != 0) { answer = false; } return answer; } } Programers - 3 _ 핸드폰 번호 가리기 내 풀이: public class Solution { public string solution(string phone_number) { string answer = ""; string fourDigits = phone_number.Substring(phone_number.Length - 4, 4) ; for(int i = 0; i < phone_number.Length - 4; i++) { answer += "*"; } answer += fourDigits; return answer; } } 다른 풀이: public class Solution { public string solution(string phone_number) { string answer = phone_number.Substring(phon.. Programers - 2 _ x만큼 간격이 있는 n개의 숫자 내 풀이: using System.Collections.Generic; public class Solution { public long[] solution(int x, int n) { List tempList = new List(); for (long i = 1; i Programers - 1 _ 직사각형 별 찍기 using System; public class Example { public static void Main() { String[] s; s = Console.ReadLine().Split(' '); int a = Int32.Parse(s[0]); int b = Int32.Parse(s[1]); for (int i = 0; i < b; i++) { for (int j = 0; j < a; j++) { Console.Write("*"); } Console.Write("\n"); } } } 이전 1 2 다음