웅재의 코딩세상
[프로그래머스] 수학, 배열2 본문
- 옷 가게 할인 받기
#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;
}
반응형
'코딩테스트 > 프로그래머스 - LV 0' 카테고리의 다른 글
[프로그래머스] 모음 제거 (3) | 2024.01.04 |
---|---|
[프로그래머스] 문자열, 반복문, 출력, 배열, 조건문 (0) | 2024.01.04 |
[프로그래머스] 수학, 배열 (1) | 2024.01.03 |
[프로그래머스] 사칙연산2 (0) | 2024.01.02 |
[프로그래머스] 배열 두 배 만들기 (1) | 2024.01.02 |