#include <string>
#include <vector>
#include <iostream>
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(int brown, int red) {
    vector<int> answer;
    
    int total = brown + red;
    int wid = 0, hei = 0;
    for(int i=3; i < total/2; i++){
        if(total % i == 0 ){
            wid = i;
            hei = total / i;
            if((wid-2) * ( hei - 2) == red){
                answer.push_back(wid);
                answer.push_back(hei);
                break;
            }
        }
    }
    answer = sort(answer);
    return answer;
}
#include <string>
#include <vector>

using namespace std;

bool solution(vector<string> phone_book) {
    bool answer = true;
    int min = phone_book[0].length();
    int min_num=0;
    for(int i=1; i < phone_book.size(); i++){
        if(phone_book[i].length() < min){
            min_num = i;
            min= phone_book[i].length();
        }
    }
    string min_s = phone_book[min_num];
    string tmp;
    
    for(int i=0; i < phone_book.size(); i++){
        if(i == min_num)
            continue;
        int cnt = 0;
        answer = true;
        
        tmp = phone_book[i];
        for(int j = 0; j < min_s.length(); j++){
            if(tmp[j] != min_s[j])
                break;
            else{
                cnt++;
            }
        }
        if(cnt == min_s.length())
        {
            answer = false;
            break;
        }
        
    }
    return answer;
}

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

[프로그래머스] 올바른 괄호  (0) 2019.07.22
[프로그래머스] 카펫  (0) 2019.07.22
[프로그래머스] 큰 수 만들기  (0) 2019.07.22
[프로그래머스] 쇠막대기  (0) 2019.07.22
[프로그래머스] 기능개발  (0) 2019.07.22
#include <string>
#include <vector>
using namespace std;

string solution(string number, int k) {
    string answer = "";
    int leng = number.length() - k;
    string ans, change;
    int ran_s = 0;
        int max = 0;
    int tmp =0;
    int j =0;
    for(int i =k; i <number.length(); i++){
        max = 0;
        for(j=ran_s; j <=i; j++){
          
            if(number[j] > max ){
                max = number[j];
                tmp = j;
            }
         }
        ran_s = tmp;
        number[tmp] = '0';
        answer+=max; 
    }
    return answer;
}

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

[프로그래머스] 카펫  (0) 2019.07.22
[프로그래머스] 전화번호 목록  (0) 2019.07.22
[프로그래머스] 쇠막대기  (0) 2019.07.22
[프로그래머스] 기능개발  (0) 2019.07.22
[프로그래머스] 스킬트리  (0) 2019.07.22
#include <string>
#include <vector>
#include <stack>
#include <iostream>
using namespace std;

int solution(string arrangement) {
    int answer = 0;
    string before;
    string now;
    stack<char>left;
    left.push(arrangement[0]);
    for(int i= 1 ; i < arrangement.length(); i++){
        before = arrangement[i-1];
        now = arrangement[i];
        if(before == ")" && now ==")"){
            left.pop();
            answer+=1;
            continue;
        }
        if(arrangement[i] == '(')
            left.push(arrangement[i]);
        else{
            cout << left.top();
            left.pop();
            answer+=left.size();
        }
        
    }
    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