웅재의 코딩세상
[프로그래머스] 문자열, 반복문, 출력, 배열, 조건문 본문
- 문자열 뒤집기
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string solution(string my_string) {
string answer = "";
reverse(my_string.begin(),my_string.end());
return my_string;
}
- 직각삼각형 출력하기
#include <iostream>
using namespace std;
int main(void) {
int n;
string s ="";
cin >> n;
for(int i=1; i<n+1; i++){
s.append(1,'*');
cout << s << endl;
}
return 0;
}
- 짝수 홀수 개수
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> num_list) {
vector<int> answer(2,0);
for(int i=0; i<num_list.size();i++){
if(num_list[i] % 2 == 0) answer[0]++;
else answer[1]++;
}
return answer;
}
- 문자 반복 출력하기
#include <string>
#include <vector>
using namespace std;
string solution(string my_string, int n) {
string answer = "";
for(int i=0; i<my_string.length(); i++){
answer.append(n,my_string[i]);
}
return answer;
}
반응형
'코딩테스트 > 프로그래머스 - LV 0' 카테고리의 다른 글
[프로그래머스] 세균 증식 (1) | 2024.01.04 |
---|---|
[프로그래머스] 모음 제거 (3) | 2024.01.04 |
[프로그래머스] 수학, 배열2 (1) | 2024.01.04 |
[프로그래머스] 수학, 배열 (1) | 2024.01.03 |
[프로그래머스] 사칙연산2 (0) | 2024.01.02 |