웅재의 코딩세상
[프로그래머스] 문자열, 정렬, 사칙연산, 수학 본문
- 모음 제거
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string solution(string my_string) {
string answer = "";
for(char& v : my_string){
if(v != 'a' && v != 'e' && v != 'i' && v != 'o' && v != 'u'){
answer += v;
}
}
return answer;
}
- 문자열 정렬하기(1)
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(string my_string) {
vector<int> answer;
for(int i=0; i< my_string.size(); i++){
if(my_string[i] >='0' && my_string[i] <= '9'){
answer.push_back(my_string[i]-'0');
}
}
sort(answer.begin(),answer.end());
return answer;
}
- 숨어있는 숫자의 덧셈(1)
#include <string>
#include <vector>
using namespace std;
int solution(string my_string) {
int answer = 0;
for(int i=0; i< my_string.size(); i++){
if(isdigit(my_string[i])) answer+= my_string[i] - '0';
}
return answer;
}
- 소인수 분해
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(int n) {
vector<int> answer;
int i=2;
while(n != 1){
if(n % i == 0){
answer.push_back(i);
n /= i;
}
else i++;
}
answer.erase(unique(answer.begin(),answer.end()),answer.end()); //vector 배열 안 중복된 항목 제거
return answer;
}
반응형
'코딩테스트 > 프로그래머스 - LV 0' 카테고리의 다른 글
[프로그래머스] 영어가 싫어요 (0) | 2024.01.10 |
---|---|
[프로그래머스] 문자열, 배열, 사칙연산, 수학, 조건문 (0) | 2024.01.09 |
[프로그래머스] 수학, 반복문 (0) | 2024.01.09 |
[프로그래머스] 조건문, 배열, 수학, 시뮬레이션 (0) | 2024.01.09 |
[프로그래머스] 수학, 문자열, 해시, 완전탐색, 조건문 (1) | 2024.01.05 |