문제 출처: https://www.acmicpc.net/problem/1065



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        
        if(N < 100){
            System.out.println(N);
            return;
        } 
        else {
            int result = 99;
            
            for(int i=100 ; i<=N ; i++){
                // 1000은 한수가 아니므로, 100~999까지 검사하면 된다. (즉, 세자리수만)
                // 숫자 CHAR(0~9)는 ASCII 코드 '0'(48)부터 시작하므로, '0'(48)을 빼면 숫자를 얻을 수 있다. 
                int diff1 = (String.valueOf(i).charAt(1)-'0'- (String.valueOf(i).charAt(0)-'0'); 
                int diff2 = (String.valueOf(i).charAt(2)-'0'- (String.valueOf(i).charAt(1)-'0');
                
                if(diff1 == diff2)
                    result++;
            }
            
            System.out.println(result);
        }
    }
}
 
cs


'Algorithm' 카테고리의 다른 글

백준 1152번: 단어의 개수  (0) 2018.10.15
백준 2448번: 별찍기-11  (0) 2018.10.04
백준 4673번: 셀프 넘버  (0) 2018.10.04
백준 2839번: 설탕 배달  (0) 2018.09.30
백준 1019번: 책 페이지  (0) 2018.09.27

문제 출처: https://www.acmicpc.net/problem/4673




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public class Main {
    
    private static int[] arr = new int[10001];
    
    public static void main(String[] args) throws Exception {
        for(int i=; i<=10000 ; i++)
            d(i);
        
        StringBuilder builder = new StringBuilder();
        for(int i=; i<=10000 ; i++)
            if(arr[i] == 0)
                builder.append(i).append("\n");
        
        System.out.println(builder);
    }
    
    public static void d(int num){
        int newNum = num;
        
           // 숫자 CHAR(0~9)는 ASCII 코드 '0'(48)부터 시작하므로, '0'(48)을 빼주면 숫자를 얻을 수 있다.
        for(int i=; i<String.valueOf(num).length() ; i++)
            newNum += String.valueOf(num).charAt(i) - '0'
        
        if(newNum <= 10000 && arr[newNum] == 0){
            arr[newNum]++;
            d(newNum);
        }
    }
}
cs


'Algorithm' 카테고리의 다른 글

백준 2448번: 별찍기-11  (0) 2018.10.04
백준 1065번: 한수  (0) 2018.10.04
백준 2839번: 설탕 배달  (0) 2018.09.30
백준 1019번: 책 페이지  (0) 2018.09.27
백준 1339번: 단어 수학  (0) 2018.09.23

문제 출처: https://www.acmicpc.net/problem/2839




최소 개수를 출력해야 하므로 3킬로그램 봉지보다 5킬로그램 봉지를 주로 써야 한다.

N이 18일 때: (3,3,3,3,3,3)=6개, (5,5,5,3)=4개


1. N을 5로 나누었을 때 나누어 떨어지는 경우, N/5을 결과 값으로 출력한다.

2. N을 5로 나누었을 때 나누어 떨어지지 않는 경우, N에서 3을 뺀다. (=3킬로그램 봉지를 사용한 꼴)

3. N의 개수가 0 이하가 될 때까지 반복한다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        int count = 0;
        
        while(N%!= && N > 0){
            N -= 3;
            count++;
        }
        
        if(N<0)
            System.out.println(-1);
        else
            System.out.println(count + N/5);
    }
}
 
cs



'Algorithm' 카테고리의 다른 글

백준 1065번: 한수  (0) 2018.10.04
백준 4673번: 셀프 넘버  (0) 2018.10.04
백준 1019번: 책 페이지  (0) 2018.09.27
백준 1339번: 단어 수학  (0) 2018.09.23
백준 1940번: 주몽  (0) 2018.09.23

+ Recent posts