개발문제해결/알고리즘 문제풀이

    백준 11399 - ATM python3

    백준 11399 - ATM python3

    # https://www.acmicpc.net/problem/11399 input() total = 0 alist = sorted(list(map(int, input().split(" ")))) for x, y in enumerate(alist): total += y while x != 0: x -= 1 total += alist[x] print(total) 처음 배열 사이즈를 받는 걸 못보고 넘기고 만들었다가 나중에 확인하게 돼서 그냥 첫째줄에 input 추가해주니 통과 끝나고 다른 사람들의 답안을 확인해보니, 내가 한방법은 좋지않은 방법인듯하다..

    정올 알고리즘 - 1856 : 숫자사각형2 python3

    생각보다 오래걸렸다.. # http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=1129&sca=2010 inputValue = input() x = int(inputValue.split(' ')[0]) y = int(inputValue.split(' ')[1]) count = 0 for idx in range(1, x+1): for sub_idx in range(1, y+1): if idx % 2 == 0: count -= 1 print(count, end=" ") else: count += 1 print(count, end=" ") if idx % 2 == 1: count = count + y + 1 else: count = count + y - 1..

    정올 알고리즘 - 1341 : 구구단2 python3

    변수를 줄여도 c보다 메모리 효율이 떨어지는 건 어쩔수 없다보다. 어짜피 줄일 수 없으면 가독성이나 높이는 것이 좋겠다 싶어 변수할당하였다. # http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=2076&sca=2010 inputValue = input() x = int(inputValue.split(' ')[0]) y = int(inputValue.split(' ')[1]) for idx in range(abs(x - y)+1): if x-y > 0: idx = idx * -1 for num in range(1, 10): print(f"{x + idx} * {num} = {str((x + idx) * num).rjust(2)} ", end="") ..

    백준 10866 - 덱

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class Main2 { static class Deque { private int deque[]; private int end = 0; public Deque(int num) { deque = new int[num]; } void push_front(int x) { for (int i = end; i > 0; i--) { deque[i] = deque[i - 1]; } deque[0] = x; end++; } void p..

    백준 10845 - 큐

    public class algo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); Queue q = new LinkedList(); int i = 0; sc.nextLine(); while (i < num) { String comand = sc.nextLine(); StringTokenizer st = new StringTokenizer(comand, " "); String firstHalf = st.nextToken(); String secondHalf = ""; if(st.hasMoreElements()) { secondHalf= st.nextToken(); } sw..

    백준 10799 - 쇠막대기

    public class algo { public static void main(String[] args) { int stickNum = 0; int sum = 0; Scanner sc = new Scanner(System.in); String temp = sc.nextLine(); char stickString[] = temp.toCharArray(); int i = 0; do { switch (stickString[i]) { case '(': stickNum++; break; case ')': if (stickString[i - 1] == '(') { stickNum--; sum += stickNum; } else if (stickString[i - 1] == ')') { stickNum--; sum+..

    백준 9012번 - 괄호

    import java.util.Scanner; public class algo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int value=0; int num = sc.nextInt(); sc.nextLine(); for (int i = 0; i < num; i++) { String line = sc.nextLine(); char[] temp = line.toCharArray(); for(int y=0; y

    자바 스택 구현

    원래 백준 10828을 풀다가 스택의 갯수의 동적할당이 아니라 명령어의 수를 동적할당으로 하라고 했는데 잘 못읽어서 만들었다. 런타임 에러 나오는 거 보고 다시 읽어봐서 발견.. 그냥 지우긴 아까워서 기록한다. 백준 10828 기반에 스택 갯수 동적할당 코드 import java.util.Scanner; public class algo { public static void main(String[] args) { int count = 0; int push = 0; Scanner sc = new Scanner(System.in); int size = sc.nextInt(); int array[] = new int[size]; while(true) { String value = sc.nextLine(); if..

    백준 11721번 - 열 개씩 끊어 출력하기

    import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String text = sc.next(); for (int i = 0; i

    백준 11720번 - 숫자의 합

    import java.util.Scanner; public class algo { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int i = sc.nextInt(); String y = sc.next(); int total=0; for(int q=0;q