코딩테스트 문제 풀이/[백준] 스택(6)
-
C# 17298번 오큰수
코드 : using System; using System.Text; using System.Collections.Generic; namespace _6 { internal class Program { static void Main(string[] args) { int N = Convert.ToInt32(Console.ReadLine()); int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); StringBuilder sb = new StringBuilder(); //오큰수를 바로 찾지 못한 값들을 넣기 위한 스택 Stack stack = new Stack(); //오큰수를 바로 찾지 못한 값들의 인덱스를 넣기 위한 스택 Sta..
2022.02.15 -
C# 1874번 스택 수열
코드 : using System; using System.Collections; using System.Collections.Generic; using System.Text; namespace _5 { internal class Program { static void Main(string[] args) { int N = Convert.ToInt32(Console.ReadLine()); Stack stack = new Stack(); StringBuilder sb = new StringBuilder(); //N = 8 이면 1부터 8을 차례로 넣을 정수 변수 int pushCount = 1; //N = 8 이면 결과적으로 8개 Pop해야 하는데 //N개만큼 잘 Pop했는지 확인하는 수 int popCoun..
2022.02.15 -
C# 4949번 균형잡힌 세상
코드 : using System; using System.Collections; using System.Text; namespace _4 { class Program { //균형잡힌 괄호 static public void balanced(Stack stack, int j, string PS) { //괄호문양이 아닐시에는 stack을 쌓지 않는다. if (PS[j] == '(' || PS[j] == ')' || PS[j] == '[' || PS[j] == ']') { //맨 초기값 if (stack.Count == 0) stack.Push(PS[j]); else { // '()' OR '[]' 모양이 만들어질때마다 pop시켜서 //stack이 올바른 괄호 문자열이라면 모두 pop될것이고 //아니라면 몇개가..
2022.02.15 -
C# 9012번 괄호
코드 : using System; using System.Collections; namespace _3 { class Program { static void Main(string[] args) { int N = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < N; i++) { string PS = Console.ReadLine(); Stack stack = new Stack(); for (int j = 0; j < PS.Length; j++) { //맨 초기값 if (stack.Count == 0) stack.Push(PS[j]); else { //"()" 모양이 만들어질때마다 pop시켜서 //stack이 올바른 괄호 문자열이라면 모두 pop될것이고 ..
2022.02.09 -
C# 10773번 제로
코드 : using System; using System.Collections; namespace _2 { class Program { static void Main(string[] args) { int N = Convert.ToInt32(Console.ReadLine()); int output = 0; Stack stack = new Stack(); for (int i = 0; i < N; i++) { int num = Convert.ToInt32(Console.ReadLine()); if (num == 0) { stack.Pop(); } else stack.Push(num); } //pop할때 stack.count가 실시간으로 줄어들어서 //정상적인 횟수만큼 돌지 않는다. //그래서 따로 변수로 만들..
2022.02.09 -
C# 10828번 스택
수정 전 코드 : using System; using System.Collections; using System.Text; namespace _1 { class Program { static void Main(string[] args) { Stack stack = new Stack(); int N = Convert.ToInt32(Console.ReadLine()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < N; i++) { string[] input = Console.ReadLine().Split(' '); switch(input[0]) { //PUSH case "push": stack.Push(input[1]); break; //POP ..
2022.02.09