#include <string>
#include <vector>

using namespace std;
vector <int> sort(vector <int> a){
    int tmp;
    for(int i=0; i < a.size()-1; i++){
        for(int j = i+1; j < a.size(); j++){
            if(a[i]> a[j]){
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }
        }
    }
    return a;
}
int cal(vector<int>arr, vector<int>target){
    vector<int> tmp;
    int value;
    int begin = target[0];
    int end = target[1];
    int num = target[2];
    for(int i=begin-1; i < end; i++){
        tmp.push_back(arr[i]);
    }    
    tmp = sort(tmp);
    value = tmp[num-1];
    return value;
}
vector<int> solution(vector<int> array, vector<vector<int>> commands) {
    vector<int> answer;
    vector <int> tmparr;
    for(int i =0; i < commands.size();i++){
        answer.push_back(cal(array, commands[i]));
    }
    return answer;
}
#include <string>
#include <vector>

using namespace std;
vector<int> sort(vector<int> a){
    int tmp = 0;
    for(int i=0; i < a.size()-1; i++){
        for(int j = i+1; j < a.size(); j++){
            if(a[i]>a[j]){
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }
        }
    }
    return a;
}
vector<int> solution(vector<int> answers) {
    vector<int> answer;
    vector <int> s1 {1, 2, 3, 4, 5};
    vector <int> s2 {2, 1, 2, 3, 2, 4, 2, 5};
    vector <int> s3 {3, 3, 1, 1, 2, 2, 4, 4, 5, 5};
    int count[4] = {0};
    for(int i=0; i < answers.size(); i++){
        if(answers[i] == s1[i % 5]){
            count[1]++;
        }
        if(answers[i] == s2[i % 8])
            count[2]++;
         if(answers[i] == s3[i % 10])
            count[3]++;
    }

    int x = count[1]>count[2] ? (count[1]>count[3] ? count[1] : count[3]) : (count[2]>count[3] ? count[2] : count[3]);
    for(int i=0; i < 4; i++){
        if(x == count[i])
            answer.push_back(i);
    }
    return answer;
}

'자윤이와고리즘 > Code' 카테고리의 다른 글

[프로그래머스] 2016년  (0) 2019.07.22
[프로그래머스] K번째 수  (0) 2019.07.22
[프로그래머스] 폰켓몬  (0) 2019.07.22
[프로그래머스] 올바른 괄호  (0) 2019.07.22
[프로그래머스] 카펫  (0) 2019.07.22
#include <vector>
using namespace std;

int solution(vector<int> nums)
{
	int answer = 0;
    vector<int> total_vec(2000000, 0);
    int total = nums.size() / 2;
    for(int i=0; i < nums.size();i++){
        total_vec[nums[i]]++;
    }
    for(int i =0; i < total_vec.size();i++){
        if(total_vec[i] != 0){
            answer ++;
        }
        if(answer == total)
            break;
    }
	return answer;
}
#include<string>
#include <stack>
#include <iostream>

using namespace std;

bool solution(string s)
{
    bool answer = true;
    stack <char> st;
    if(s[0] == '('){
        //st.push(s[0]);
        for(int i =0; i < s.length(); i++){
            char ss = s[i];
            if(ss == '(')
                st.push(ss);
            else{
                if(!st.empty())
                    st.pop();
                else{
                    answer = false;
                    break;
                }
            }
            if(st.empty())
                answer = true;
            else
                answer = false;
         }
    }
    else
        answer = false;
    
    return answer;
}

'자윤이와고리즘 > Code' 카테고리의 다른 글

[프로그래머스] 모의고사  (0) 2019.07.22
[프로그래머스] 폰켓몬  (0) 2019.07.22
[프로그래머스] 카펫  (0) 2019.07.22
[프로그래머스] 전화번호 목록  (0) 2019.07.22
[프로그래머스] 큰 수 만들기  (0) 2019.07.22

+ Recent posts