웅재의 코딩세상
[프로그래머스] 배열, 구현, 수학 본문
- 배열 자르기
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> numbers, int num1, int num2) {
vector<int> answer(numbers.begin() + num1, numbers.begin() + num2+1);
return answer;
}
- 외계행성의 나이
#include <string>
#include <vector>
using namespace std;
string solution(int age) {
string answer = "";
while(age != 0){
answer = (char)(age % 10 + 97) + answer;
age /= 10;
}
return answer;
}
- 진료순서 정하기
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> emergency) {
vector<int> answer;
vector<int> v(emergency);
sort(v.begin(), v.end(), greater<>());
for(int i=0; i<emergency.size();i++){
for(int j=0; j<emergency.size(); j++){
if(v[j] == emergency[i]) answer.push_back(j+1);
}
}
return answer;
}
- 순서쌍의 개수
#include <string>
#include <vector>
using namespace std;
int solution(int n) {
int answer = 0;
for(int i=1; i<n+1; i++){
if(n % i == 0) answer++;
}
return answer;
}
반응형
'코딩테스트 > 프로그래머스 - LV 0' 카테고리의 다른 글
[프로그래머스] 수학, 문자열, 해시, 완전탐색, 조건문 (1) | 2024.01.05 |
---|---|
[프로그래머스] 모스부호(1) (1) | 2024.01.05 |
[프로그래머스] 진료 순서 정하기 (0) | 2024.01.05 |
[프로그래머스] 문자열, 조건문, 수학, 반복문 (0) | 2024.01.05 |
[프로그래머스] 세균 증식 (1) | 2024.01.04 |