코딩테스트/프로그래머스 - LV 0
[프로그래머스] 문자열, 조건문, 수학, 반복문
웅드
2024. 1. 5. 10:40
- 특정 문자 제거하기
#include <string>
#include <vector>
using namespace std;
string solution(string my_string, string letter) {
string answer = "";
for(int i=0; i<my_string.length(); i++){
if(my_string[i] != letter[0]) answer += my_string[i];
}
return answer;
}
- 각도기
#include <string>
#include <vector>
using namespace std;
int solution(int angle) {
if(0 < angle && angle < 90) return 1;
else if(angle ==90) return 2;
else if(90 < angle && angle < 180) return 3;
else if(angle == 180) return 4;
}
- 양꼬치
#include <string>
#include <vector>
using namespace std;
int solution(int n, int k) {
return n*12000 + (k-(n/10))*2000;
}
- 짝수의 합
#include <string>
#include <vector>
using namespace std;
int solution(int n) {
int answer=0;
for(int i=1; i<=n; i++){
if(i%2==0) answer +=i;
}
return answer;
}
반응형