728x90
반응형

백준 24

[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#] 백준 알고리즘 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

[C#] 백준 알고리즘 2439번, 별 찍기 -2

using System; namespace codingstudy { class Program { static void Main() { int n = int.Parse(Console.ReadLine()); // 입력 for (int i=1; i=i+1; j--) // j가 n의 값에서 -1되어 공백을 채우도록 for문 { Console.Write(" "); } for(int k=1; k=i+1이 >로 되어있어서 이 부분을 수정해주었더니 정답이 나왔다. using System; namespace codingstudy { class Program { static void Main() { int n = int.Parse(Console.ReadLine()); int j=n; int k=1; for (int i =..

C#/C# (백준) 2023.01.12

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

using System; namespace codingstudy { class Program { static void Main() { int t = int.Parse(Console.ReadLine()); // 테스트 케이스 입력 int sum = 0; for (int i = 0; i < t; i++) { string[] s = Console.ReadLine().Split(); // 더할 값 입력 int num1 = int.Parse(s[0]); int num2 = int.Parse(s[1]); sum = num1 + num2; Console.WriteLine($"Case #{i+1}: {num1} + {num2} = {sum}"); } } } } 이전 문제의 코드에서 Console.WriteLine부분만..

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