본문 바로가기
반응형

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

백준 C# - 10828 Queue 알아보러가기 백준 C# - 10845 Stack 알아보러가기 백준 C# - 10828 stack을 활용하면 금방 풀리는 문제였다. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace baek2 { class Program { static void Main(string[] args) { int nu code-piggy.tistory.com using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace baek2 { class Program { static void Mai.. 2023. 9. 22.
백준 C# - 1406 +) 문제 설명,풀이 계속 시간초과가 나와서 열받은 문제 시도 풀이 방법 01 String 첫번째로 StringBuilder로 풀었는데 금방 풀려서 신나게 제출했다. 근데 계속 시간초과가 나와서 뭐가 잘못 됐나 봤더니 Stack 2개 or LinkedList로 풀어야 한다는 정보를 얻었다. 02 LinkedList 코드도 짧게 잘 짠 것 같은데 계속 2%가 되면 틀렸습니다가 나왔다. 하루 종일 반례를 못찾다가 질문 게시판에 반례하나를 보고 이마를 탁 쳤다. if (cursor.Value != sb.First.Value && cursor.Previous != null) 틀렸습니다의 원인은 LinkedList첫번째 Value와 cursor.Value가 같아야 되는 조건을 사용한 것이었다. aaa 4 L B D B 풀이 문제의 커.. 2023. 9. 22.
백준 C# - 1874(+) 문제 설명 및 풀이) 1874 문제를 읽는데 무슨 내용인지 이해가 하나도 안갔다. 그래서 여러 블로그들을 찾아보면서 내용 설명과 코드를 봐도 이해가 안가서 문제 이해하는데에 제일 시간을 많이 소모했다... 문제 설명 2가지만 알면된다. 1.n이 stack에 있는가? 2. stack.Peek()==n인가? 위의 그림을 이용해서 예시를 풀어보자 예시 01 3 2 1 3 예시 02 2번째 1에서 stack.Peek()이 1이 아니므로 결과가 0이 나온다. 3 3 1 2 코드 01 변수 설정 int num = int.Parse(Console.ReadLine()); Stack stack = new Stack(); StringBuilder sb = new StringBuilder(); bool isNO = false; int count.. 2023. 9. 20.
백준 C# - 9012 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace baek2 { class Program { static void Main(string[] args) { int num = int.Parse(Console.ReadLine()); for (int i = 0; i < num; i++) { string answer = "YES"; string s = Console.ReadLine(); int balance = 0; for (int j = 0; j < s.Length; j++) { if (s[j] == '(') { balance++; } else { balance--; } if (balance.. 2023. 9. 19.
백준 C# - 9098 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace baek2 { class Program { static void Main(string[] args) { int num = int.Parse(Console.ReadLine()); for (int i = 0; i 2023. 9. 17.
백준 C# - 2501 using System; using System.Collections.Generic; namespace baek2 { class Program { static void Main(string[] args) { string n_string = Console.ReadLine(); string[] token = n_string.Split(); int n = int.Parse(token[0]); int k = int.Parse(token[1]); int a = n; List pig = new List(); while (a > 0) { if (n % a == 0) { pig.Add(a); } a--; } pig.Sort(); if (pig.Count < k) Console.WriteLine(0); else Cons.. 2023. 7. 18.
반응형