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



참고출처 

http://mygumi.tistory.com/180?category=689691https://www.slideshare.net/Baekjoon/baekjoon-online-judge-1019


N이 36일 때,

 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 32 33 34 35 36


10~29는 일의 자리가 0~9까지 한 번씩 나오며, 십의자리에서 숫자 1와 2는 열 번씩 나온다. 


1) 1~9와 30~36의 숫자는 각 숫자가 몇 번씩 나오는지 일일이 계산해 더한다. 

이때, 1에서부터는 끝자리가 0이 나올 때까지 더해주고, 36에서부터 끝자리가 9가 나올 때까지 빼면서 계산한다.

 

2) 10~29까지의 숫자는 일의 자리, 십의 자리씩 끊어서 계산한다.

십의 자리가 1와 2일 때, 일의 자리에서 0~9는 총 (2-1+1)*1번씩 나오고, 십의 자리에서 1와 2는 1*10번씩 나온다. 

 


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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    
    private static int[] numArr = new int[10];
    private static int position = 1;
    
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine()); // 36
        int start = 1;
        int end = N;
        
        while(start <= end) {
            
            while(start%10!=&& start<=end){
                cal(start);
                start++// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            }
            
            if(start > end)
                break// 계산 종료
            
            while(end%10!=&& start<=end){
                cal(end);
                end--// 36, 35, 34, 33, 32, 31, 30, 29
            }
            
            start /= 10;  // 10 -> 1 
            end /= 10;  // 29 -> 2
            
            for(int i=; i<10 ; i++)
                numArr[i] += (end-start+1* position;  // 일의 자리에 0~9가 총 2번씩 등장
            
            position *= 10;  // 자리수 계산
        }
        
        StringBuilder builder = new StringBuilder();
        for(int i=; i<10 ; i++)
            builder.append(numArr[i] + " ");
        
        System.out.println(builder.toString());
    }
    
    public static void cal(int num){ // 각 숫자가 몇 번씩 나오는지 더함
        while(num > 0){
            numArr[num%10+= position;
            num /= 10;
        }
    }
}
cs


'Algorithm' 카테고리의 다른 글

백준 4673번: 셀프 넘버  (0) 2018.10.04
백준 2839번: 설탕 배달  (0) 2018.09.30
백준 1339번: 단어 수학  (0) 2018.09.23
백준 1940번: 주몽  (0) 2018.09.23
백준 1834번: 나머지와 몫이 같은 수  (0) 2018.09.22

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




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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
 
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());
        
        String[] inputArr = new String[N];
        for(int i=; i<N ; i++)
            inputArr[i] = reader.readLine();
        
        ArrayList<Character> alphabet = new ArrayList<>();
        ArrayList<Integer> number = new ArrayList<>();
        
        for(int i=; i<N ; i++){
            String str = inputArr[i];
            for(int j=; j<str.length() ; j++){
                if(!alphabet.contains(str.charAt(j))){
                    alphabet.add(str.charAt(j));
                    number.add((int)Math.pow(10, str.length()-j-1));
                }
                else{
                    int index = alphabet.indexOf(str.charAt(j));
                    number.set(index, number.get(index) + (int)Math.pow(10, str.length()-j-1));
                }
            }
        }
        
        int result = 0;
        int n = 9;
        
        while(!number.isEmpty()){
            int max = 0;
            int index = 0;
            
            for(int i=; i<number.size() ; i++){
                if(max < number.get(i)){
                    max = number.get(i);
                    index = i;
                }
            }
            result += max * n--;
            number.remove(index);
        }
        
        System.out.println(result);
    }
}
cs





'Algorithm' 카테고리의 다른 글

백준 2839번: 설탕 배달  (0) 2018.09.30
백준 1019번: 책 페이지  (0) 2018.09.27
백준 1940번: 주몽  (0) 2018.09.23
백준 1834번: 나머지와 몫이 같은 수  (0) 2018.09.22
백준 1780번: 종이의 개수  (0) 2018.08.08

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



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
32
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
 
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 M = Integer.parseInt(reader.readLine());
        int count = 0;
        
        ArrayList<String> list = new ArrayList<>();
        StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
        for(int i=; i<N ; i++)
            list.add(tokenizer.nextToken());
 
        while(list.size() > 1){
            int value1 = Integer.parseInt(list.get(0));
            int value2 = M - value1;
            if(list.contains(String.valueOf(value2)) && value1!=value2){
                count++;
                list.remove(String.valueOf(value2));
            }
            list.remove(0);
        }
        
        System.out.println(count);
    }
}
cs



'Algorithm' 카테고리의 다른 글

백준 1019번: 책 페이지  (0) 2018.09.27
백준 1339번: 단어 수학  (0) 2018.09.23
백준 1834번: 나머지와 몫이 같은 수  (0) 2018.09.22
백준 1780번: 종이의 개수  (0) 2018.08.08
백준 1992번: 쿼드트리  (0) 2018.08.08

+ Recent posts