본문 바로가기

알고리즘/백준

(87)
[문제] 백준 1065번 한수 (쉬운 문제를 너무 복잡하게 풀었다) * 백준 단계별로 풀어보기: 함수편 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int sum = 0; for(int i=1;i
[문제] 백준 4673번 셀프넘버 * 단계별로 풀어보기 : 함수 public class Main { public static void main(String[] args) { boolean check[] = new boolean[10000]; int self = 0; for(int d=0;d
[문제] 백준 8958번 OX 퀴즈 * 단계별로 풀어보기: 1차원 배열 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String score[] = new String[n]; for (int i = 0; i < n; i++) { score[i] = sc.next(); } for (int i = 0; i < n; i++) { int len = score[i].length(); int sum = 0; for (int j = 0; j < len; j++) { if (score[i].charAt(j) == 'O') { int k = j..
[문제] 백준 4344번 평균은 넘겠지 * 단계별로 풀어보기: 1차원 배열 import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] score = new int[n][]; for(int i=0;i
[문제] 백준 1110번 더하기 사이클 * 단계별로 풀어보기: while 문 문제 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int cycle = 0; int tmp = n, sum = 0; while(true) { if(n99) break; sum = (tmp/10) + (tmp%10); tmp = (tmp%10)*10 + (sum%10); cycle++; if(n == tmp) break; } System.out.println(cycle); } }
[문제] 코드업 1930번 supersum- 메모이제이션으로 풀기 메모이제이션 기법을 처음 알았다!! 이해하는데 좀 걸렸다. import java.util.Scanner; public class supersum { public static void main(String[] args) { int memo[][] = new int[15][15]; Scanner sc = new Scanner(System.in); int k,n; while(sc.hasNextInt()) { k = sc.nextInt(); n = sc.nextInt(); init(memo); System.out.println(func(k,n,memo)); } } static int func(int k, int n, int[][] m) { int result = 0; if(m[k][n]>0) return m[k..
[알고리즘]백준 1339번 단어 수학 문제: https://www.acmicpc.net/problem/1339 1339번: 단어 수학 첫째 줄에 단어의 개수 N(1 ≤ N ≤ 10)이 주어진다. 둘째 줄부터 N개의 줄에 단어가 한 줄에 하나씩 주어진다. 단어는 알파벳 대문자로만 이루어져있다. 모든 단어에 포함되어 있는 알파벳은 최대 www.acmicpc.net #include #include #include #include using namespace std; bool desc(int a, int b) { return a > b; } int main() { //ios::sync_with_stdio(false); int alphabet[26] = { 0, }; int n;//단어의 개수 cin >> n; int answer = 0;//정답 f..