본문 바로가기
반응형

코딩테스트 준비/백준 C#161

백준 C# - 10820 +)풀이 풀이 알고리즘 자체는 쉽게 떠올릴 수 있다. 하지만 입력부분에서 한줄로 입력받는 것이 아니라 한꺼번에 N개의 문자열을 받는 것이 조금 까다로웠다. 입력 첫째 줄부터 N번째 줄까지 문자열이 주어진다. (1 ≤ N ≤ 100) 문자열의 길이는 100을 넘지 않는다. Console.ReadLine은 한줄씩만 받아올 수 있는데 어떻게 할까 하다가 null을 입력받기 전까지 계속 반복문으로 입력을 받자라는 아이디어로 아래와 같이 입력받았다. while ((word = Console.ReadLine()) != null) 코드 전문 using System; using System.Linq; namespace baek2 { class Program { static void Main(string[] args) { str.. 2023. 10. 23.
백준 C# - 10809 이 문제를 풀기 전에 아래 문제를 먼저 푸는 것을 추천한다. 백준 C# - 10808 백준 C# - 10808 using System; using System.Collections.Generic; using System.Text; namespace baek2 { class Program { static void Main(string[] args) { string word = Console.ReadLine(); int[] vs = new int[26]; foreach(char c in word) { vs[c - 'a']++; } for(int i = 0; i code-piggy.tistory.com using System; using System.Linq; namespace baek2 { class Pro.. 2023. 10. 23.
백준 C# - 10808 using System; using System.Collections.Generic; using System.Text; namespace baek2 { class Program { static void Main(string[] args) { string word = Console.ReadLine(); int[] vs = new int[26]; foreach(char c in word) { vs[c - 'a']++; } for(int i = 0; i 2023. 10. 23.
백준 C# - 1918 +) 풀이 이 문제를 풀기전에 아래 문제를 먼저 푸는 것을 추천한다. 백준 C# - 1935 백준 C# - 1935 +) 풀이 풀이 후위 표기법으로 계산하는 문제이다. 제시받은 문자열안의 문자들을 순서대로 확인하여 연산자인지 피연산자인지 확인한다. 만약 피연산자인 경우 stack에 push하고 연산자인 경우 두번의 Po code-piggy.tistory.com 중위 표기법에서 후위 표기법으로 바꾸는 문제이다. 중위 표기법에서 후위표기법으로 바꿀때 연선자 우선순위를 고려해야 한다. 01 우선순위 메서드 static int Precedence(char c) { switch (c) { case '+': case '-': return 1; case '*': case '/': return 2; default: return .. 2023. 10. 20.
백준 C# - 1935 +) 풀이 풀이 후위 표기법으로 계산하는 문제이다. 제시받은 문자열안의 문자들을 순서대로 확인하여 연산자인지 피연산자인지 확인한다. 만약 피연산자인 경우 stack에 push하고 연산자인 경우 두번의 Pop을 통해 연산을 수행하도록한다. 예제 문제 풀이 5 ABC*+DE/- 1 2 3 4 5 과정 그림과 같이 흐름만 알게된다면 쉽게 풀 수 있다. 코드 using System; using System.Collections.Generic; namespace baek2 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string line = Console.ReadLine(); int[] array = new.. 2023. 10. 20.
백준 C# - 17298 +) 풀이 시간초과 문제를 보고 어 쉽네? 이렇게 풀다가 시간초과가 나왔다. int n = int.Parse(Console.ReadLine()); string line = Console.ReadLine(); string[] token = line.Split(' '); int[] A = new int[n]; StringBuilder answer = new StringBuilder(); for (int i = 0; i < n; i++) { A[i] = int.Parse(token[i]); } int[] NGE = new int[n]; for (int i = 0; i < n; i++) { int max = -1; for (int j = i + 1; j < n; j++) { if (A[i] < A[j]) { max = A.. 2023. 10. 17.
반응형