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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제에 제시된 제한 사항(1)
문제에 제시된 제한 사항(2)
입출력 예시

 

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
#include <iostream>
#include <string>
#include <vector>
#include <queue>
 
using namespace std;
 
int solution(int bridge_length, int weight, vector<int> truck_weights) {
    int answer = 0//걸린시간
    queue<pair<intint>> on_bridge; //다리 위 트럭
    queue<int> cp_tw;
    int total_weights = 0// 현재 다리 위 트럭의 총 무게
    int cnt = 0;  //건너간 트럭의 수
 
    for (int i = 0; i < truck_weights.size(); i++) {
        cp_tw.push(truck_weights[i]);
    }
 
    //트럭이 다 건너갈 때까지 반복
    while (cnt != truck_weights.size()) {
        if (on_bridge.size() != 0) {
            for (int i = 0; i < on_bridge.size(); i++) {
                pair<intint> tmp(on_bridge.front().first + 1, on_bridge.front().second);
                on_bridge.pop();
                on_bridge.push(tmp);
            }
            if (on_bridge.front().first == bridge_length) {
                total_weights -= on_bridge.front().second;
                on_bridge.pop();
                cnt++;
            }
        }
        if (!cp_tw.empty()) {
            if (total_weights + cp_tw.front() <= weight) {
                total_weights += cp_tw.front();
                on_bridge.push(make_pair(0, cp_tw.front()));
                cp_tw.pop();
            }
        }
 
        answer++;
    }
    return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
반응형

'알고리즘(C++) > 프로그래머스 level2' 카테고리의 다른 글

쇠막대기  (0) 2020.04.04
  (0) 2020.04.04
스킬트리  (0) 2020.04.04
124 나라의 숫자  (0) 2020.04.04
프린터  (0) 2020.04.04

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제에 제시된 예시 그림
문제에 제시된 제한 사항(1)
문제에 제시된 제한 사항(2)
문제에 제시된 제한 사항(3)
입출력 예시

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
#include <string>
#include <vector>
 
using namespace std;
 
int solution(string arrangement) {
    int answer = 0;
    vector<char> stack;
 
    for (int i = 0; i < arrangement.size(); i++) {
        if (arrangement[i] == '(') {
            stack.push_back(arrangement[i]);
        }
        else {
            stack.pop_back();
            if (arrangement[i - 1== ')') {
                answer++;
            }
            else {
                answer += stack.size();
            }
        }
    }
    return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter

 

반응형

'알고리즘(C++) > 프로그래머스 level2' 카테고리의 다른 글

다리를 지나는 트럭  (0) 2020.04.29
  (0) 2020.04.04
스킬트리  (0) 2020.04.04
124 나라의 숫자  (0) 2020.04.04
프린터  (0) 2020.04.04

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제에 제시된 제한 사항
입출력 예시

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <string>
#include <vector>
 
using namespace std;
 
vector<int> solution(vector<int> heights) {
    vector<int> answer;
    answer.push_back(0);
    for (int i = 1; i < heights.size(); i++) {
        int j = i-1;
        while (j >= 0) {
            if (heights[i] < heights[j]) {
                answer.push_back(j + 1);
                break;
            }
            j--;
        }
        if (j < 0) {
            answer.push_back(0);
        }
    }
 
    return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter

 

반응형

'알고리즘(C++) > 프로그래머스 level2' 카테고리의 다른 글

다리를 지나는 트럭  (0) 2020.04.29
쇠막대기  (0) 2020.04.04
스킬트리  (0) 2020.04.04
124 나라의 숫자  (0) 2020.04.04
프린터  (0) 2020.04.04

https://programmers.co.kr/learn/courses/30/lessons/49993?language=cpp

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제에 제시된 제한 사항(1)
문제에 제시된 제한 사항(2)
입출력 예시

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
#include <string>
#include <vector>
 
using namespace std;
 
int solution(string skill, vector<string> skill_trees) {
    int answer = 0;
    for (int i = 0; i < skill_trees.size(); i++) {
        int check = 0;
        string tmp = skill_trees[i];
        for (int j = 0; j < tmp.size(); j++) {
            //skill_trees의 현재 문자가 skill 문자열 내에 있는 문자인지 확인
            if (skill.find(tmp[j],0!= string::npos) {
                //skill의 문자열의 순서와 맞는 문자인지 확인
                if(tmp[j] == skill[check]){
                    check++;
                }
                else {
                    break;
                }
            }
            if (j == tmp.size() - 1) answer++;
        }
        //정상적으로 비교가 끝났다면 answer를 ++;
    }
        return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter

 

반응형

'알고리즘(C++) > 프로그래머스 level2' 카테고리의 다른 글

쇠막대기  (0) 2020.04.04
  (0) 2020.04.04
124 나라의 숫자  (0) 2020.04.04
프린터  (0) 2020.04.04
기능개발  (0) 2020.04.04

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제에 제시된 제한 사항(1)
문제에 제시된 제한 사항(2)
입출력 예시

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <string>
#include <vector>
 
using namespace std;
 
string solution(int n) {
    string answer = "";
 
    while (n > 0) {
        if (n % 3 == 0) {
            answer.insert(0"4");
            n = n / 3 - 1;
        }
        // % 3의 결과가 1,2 인 경우
        else {
            answer.insert(0, to_string(n % 3));
            n = n / 3;
        }
        
    }
    return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter

 

반응형

'알고리즘(C++) > 프로그래머스 level2' 카테고리의 다른 글

  (0) 2020.04.04
스킬트리  (0) 2020.04.04
프린터  (0) 2020.04.04
기능개발  (0) 2020.04.04
주식가격  (0) 2020.04.04
 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제에 제시된 제한 사항(1)
문제에 제시된 제한 사항(2)
입출력 예시

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
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
 
using namespace std;
 
int solution(vector<int> priorities, int location) {
    int answer = 0;
    queue<int> pq;
    int idx = 0;
    while (pq.size() != priorities.size()) {
        int max_value = *max_element(priorities.begin(), priorities.end());
         if(priorities[idx%priorities.size()] == max_value){
            pq.push(idx%priorities.size());
            priorities[idx%priorities.size()] = 0;
        }
        idx++;
    }
        
    while (!pq.empty()) {
        answer++;
        if(pq.front() == location){
            return answer;
        }
        pq.pop();
    }
    return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter

 

반응형

'알고리즘(C++) > 프로그래머스 level2' 카테고리의 다른 글

  (0) 2020.04.04
스킬트리  (0) 2020.04.04
124 나라의 숫자  (0) 2020.04.04
기능개발  (0) 2020.04.04
주식가격  (0) 2020.04.04

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제에 제시된 제한 사항
입출력 예시

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
#include <string>
#include <vector>
 
using namespace std;
 
vector<int> solution(vector<int> progresses, vector<int> speeds) {
    vector<int> answer;
 
    while(!progresses.empty()){ 
        for (int i = 0; i < progresses.size(); i++) {
            if (progresses[i] < 100) {
                progresses[i] += speeds[i];
            }
        }
        int a = 0;
        while(!progresses.empty() && progresses[0>= 100) {
            progresses.erase(progresses.begin());
            speeds.erase(speeds.begin());
            a++;
        }
        if (a) { answer.push_back(a); }
    }
    
 
    return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter

 

반응형

'알고리즘(C++) > 프로그래머스 level2' 카테고리의 다른 글

  (0) 2020.04.04
스킬트리  (0) 2020.04.04
124 나라의 숫자  (0) 2020.04.04
프린터  (0) 2020.04.04
주식가격  (0) 2020.04.04

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제에 제시된 제한 사항
입출력 예시

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <string>
#include <vector>
 
using namespace std;
 
vector<int> solution(vector<int> prices) {
    vector<int> answer;
    for (int i = 0; i < prices.size(); i++) {
        int a = 0;
        for (int j = i+1; j < prices.size(); j++) {
            a++;
            if (prices[i] > prices[j]) {
                break;
            }
            
        }
        answer.push_back(a);
    }
    return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter

 

반응형

'알고리즘(C++) > 프로그래머스 level2' 카테고리의 다른 글

  (0) 2020.04.04
스킬트리  (0) 2020.04.04
124 나라의 숫자  (0) 2020.04.04
프린터  (0) 2020.04.04
기능개발  (0) 2020.04.04

+ Recent posts