#include <string>
#include <vector>

using namespace std;

string solution(string s) {
    string answer = "";
    int leng = s.length();

    if(leng%2 ==0){
        for(int i=leng/2-1; i <=leng/2; i++)
            answer += s[i];
    }
    else
        answer = s[leng/2];
    return answer;
}
#include <string>
#include <vector>
#include <iostream>
using namespace std;

string solution(int a, int b) {
    string answer = "";
    int value = 0;
    vector<int>month{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    vector<string>date {"FRI", "SAT","SUN", "MON", "TUE", "WED", "THU"};
    for(int i=0; i <a-1; i++){
        value = (value + month[i]% 7) % 7;
    }
    value =(value+ b % 7 -1)%7;

    answer = date[value];
    return answer;
}
#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

+ Recent posts