웅재의 코딩세상

[프로그래머스] 수학, 배열2 본문

코딩테스트/프로그래머스 - LV 0

[프로그래머스] 수학, 배열2

웅드 2024. 1. 4. 14:13
  • 옷 가게 할인 받기
#include <string>
#include <vector>

using namespace std;

int solution(int price) {
    
    if(price >=500000){
        price = price*0.8;
    }
    else if(price >= 300000){
        price = price*0.9;
    }
    else if(price>=100000){
        price = price*0.95;
    }

    return price;
}
  • 아이스 아메리카노
#include <string>
#include <vector>

using namespace std;

vector<int> solution(int money) {
    vector<int> answer;
    answer.push_back(money / 5500);
    answer.push_back(money % 5500);
    return answer;
}
  • 나이 출력
#include <string>
#include <vector>

using namespace std;

int solution(int age) {
    
    return 2022 - age + 1;
}
  • 배열 뒤집기
#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<int> num_list) {
    vector<int> answer;
    for(int i = num_list.size(); i>0; i--){
        answer.push_back(num_list[i-1]);
    }
    return answer;
}
반응형