728x90
반응형

C#/C# (백준) 35

[C#] 백준 알고리즘 1427번, 소트인사이드

1. Linq 사용 using System; using System.Linq; public class Sample { public static void Main() { // Array.Sort() : 오름차순으로 배열을 정렬 // 내림차순으로 정렬하는 메서드는 없으므로 Sort() 호출 후 Reverse() 메서드를 사용 string input = Console.ReadLine(); // 예외처리 // if (!int.TryParse(input, out int _)) // { // Console.WriteLine("Invalid input."); // return; // } int[] arr = input.Select(c => int.Parse(c.ToString())).ToArray(); Array.S..

C#/C# (백준) 2023.02.23

[C#] 백준 알고리즘 4344번, 평균은 넘겠지

while using System; namespace codingstudy { class Program { static void Main() { int c = int.Parse(Console.ReadLine()); // 테스트 케이스 int[] scores; double avg; int cnt; while (c --> 0) { // 첫번째 요소를 제외한 나머지 문자열들을 배열로 추출 scores = Array.ConvertAll(Console.ReadLine().Split()[1..],int.Parse); // Average() 메서드로 배열의 평균 구하기 avg = scores.Average(); // Count() 메서드로 배열의 건수 구하기 // 람다식으로 scores배열에서 개별 점수가 평균보다 ..

C#/C# (백준) 2023.02.07

[C#] 백준 알고리즘 10807번, 개수 세기

내가 쓰다가 요상해진 코드 using System; using System.Linq; namespace codingstudy { class Program { static void Main() { int count = 0; int[] input; int v; int n = int.Parse(Console.ReadLine()); // 정수 개수 입력 for (int i = 0; i < n; i++) { input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // n만큼 input 배열에 저장 } // 찾으려고 하는 정수 v v = int.Parse(Console.ReadLine()); foreach(int n in input) { if (input..

C#/C# (백준) 2023.01.31

[C#] 백준 알고리즘 10951번, A+B - 4

using System; namespace codingstudy { class Program { static void Main() { while (true) { string input = Console.ReadLine(); if (input == null) break; string[] s = input.Split(); int num1 = int.Parse(s[0]); int num2 = int.Parse(s[1]); int sum = num1 + num2; Console.WriteLine(sum); } } } } 처음에는 5번 문제를 먼저 풀었어서 5번 문제에서 조금 수정하고 답을 냈다. 근데 런타임 에러가 난 것이다. 뭐지? ? 하고 질문을 봤더니 이 문제의 요점은 끝나는 지점이 없기 때문에 런타임 에..

C#/C# (백준) 2023.01.12

[C#] 백준 알고리즘 10952번, A+B - 5

using System; namespace codingstudy { class Program { static void Main() { int sum = 0; int num1=1, num2=1; while (num1!=0 && num2!=0) { string[] s = Console.ReadLine().Split(); // 더할 값 입력 num1 = int.Parse(s[0]); num2 = int.Parse(s[1]); sum = num1 + num2; if (num1!=0 && num2!=0) { Console.WriteLine($"{sum}"); } } } } } 맞긴 맞았는데 메모리가 너무 많은 것 같다고 느꼈다.. 언어따라 다른지 모르겠지만 1KB인 사람도 있었으니.. 나도 좀 줄여봐야겠다 usi..

C#/C# (백준) 2023.01.12
728x90
반응형