2025/08 5

주사위의 개수 (복습 완료)

개선 코드직접 계산반복문 안 쓰고, 배열 인덱스로 직접 접근 (가로 * 세로 * 높이) using System;public class Solution { public int solution(int[] box, int n) { return (box[0] / n) * (box[1] / n) * (box[2] / n); }} LINQ 사용using System;using System.Linq;public class Solution { public int solution(int[] box, int n) { return box.Select(length => length / n).Aggregate(1, (a, b) => a * b); }}box.Select(length..

C#/복습 완료 2025.08.21

직각삼각형 출력하기 (복습 완료)

개선된 코드 이중 반복문 -> 단일 반복문for (int i = 1; i new string('*', i) : *를 i개 만듦 ! cf) 참고 : 다른 한 줄 방법들 LINQusing System;using System.Linq; // LINQ가 아니라! public class Example{ public static void Main() { int n = int.Parse(Console.ReadLine()); Enumerable.Range(1, n).ToList() .ForEach(i => Console.WriteLine(new string('*', i))); }}- Enumerable.Range(1, n) : 1부터 n까지 숫..

C#/복습 완료 2025.08.14

[C#]숨어있는 숫자의 덧셈(1) - 복습 완료

개선 코드LINQ 버전using System;using System.Linq;public class Solution { public int solution(string my_string) { return my_string.Where(char.IsDigit).Sum(ch => ch - '0'); }}- Where(char.IsDigit) : char.IsDigit 메서드를 각 문자에 적용해서 숫자인 것만 필터링- Sum(ch => ch - '0') : 필터링된 각 char에 대해 ch - '0' 변환 후 합계 +) char.IsDigit(string, index) 사용해서 푼 버전* index가 필요하므로, foreach말고 for문 쓰 (가능하긴함)using System;usi..

C#/복습 완료 2025.08.07

[C#]문자 반복 출력하기 (프로그래머스) - (복습 완료)

개선 코드* Linqusing System;using System.Linq;public class Solution { public string solution(string my_string, int n) { return string.Concat(my_string.Select(ch => new string(ch, n))); }}.Select : 문자열의 각 문자(ch)를 변환ch => new string(ch, n) : 각 문자를 n번 반복한 문자열로 변환.Concat : 변환된 문자열을 하나로 합침 => 문자열의 각 문자를 -> 그 문자를 n번 반복한 문자열로 바꿔서 -> 모두 합쳐줘 cf. 다른 LINQ 방법return new string(my_string.SelectMany(c..

C#/복습 완료 2025.08.07

[C#]분수의 덧셈(프로그래머스) - 복습 필요(9/8)

개선 코드 또 새로푼 것 * 에러-> 눈을 씻고 찾아봐도 21번째 무리가 없는데... 20번째에서 ;을 빠뜨렸다 ! 시도using System;// 입력 : 첫 번째 분수 분자 nemer1, 분모 denom1 / 분자 numer2, denom2 // 출력 : 두 분수를 더한 분수 -> 기약 분수 / 정수 분자, 정수 분모 배열 answer public class Solution { public int[] solution(int numer1, int denom1, int numer2, int denom2) { //int[] answer = new int[] {}; int tempNumer = 0; int tempDenom = 0; ..

C#/복습 필요 2025.08.04