Recent Posts
«   2024/12   »
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
Today
Total
관리 메뉴

Try

[Programmers/C++] 큰 수 만들기 본문

Algorithm/Programmers

[Programmers/C++] 큰 수 만들기

HAS3ONG 2019. 3. 23. 22:40

출처


https://programmers.co.kr/learn/courses/30/lessons/42883





소스



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
#include <string>
#include <iostream>
using namespace std;
 
string solution(string number, int k) {
    string answer = "";
    int length = 0;
    length = number.length();
    int cnt = 0;
    int len = k;
    int flag = 0;
    k = length - k;
    
    while(1){
        for(int j = 0; j < length; j++){
            
            for(int m = 1; m <= len; m++){
                
                if(number[j] >= number[j+m]){
                    continue;
                }
                else{
                    flag = 1;
                }
                
                if (flag){
                    break;
                }
            }
            
            if(flag){
                len = len - 1;
                flag = 0;
            }
            else{
                answer += number[j];
                cnt++;
            }
            
            if(cnt >= k){
                return answer;
            }
        }
    }
    return answer;
}
cs


Comments