웅재의 코딩세상
[프로그래머스] 문자열, 배열, 조건문 본문
- 7의 개수
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> array) {
int answer = 0;
for(int i=0; i< array.size(); i++){
while(array[i] != 0){
if(array[i] % 10 == 7){
answer++;
}
array[i] /=10;
}
}
return answer;
}
- 잘라서 배열로 저장하기
#include <string>
#include <vector>
using namespace std;
vector<string> solution(string my_str, int n) {
vector<string> answer;
string s="";
for(int i=0; i<my_str.size(); i++){
if((i+1)%n == 0) {
s+= my_str[i];
answer.push_back(s);
s = "";
}
else{
s+= my_str[i];
}
}
if(!empty(s)) answer.push_back(s);
return answer;
}
- 중복된 숫자 개수
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> array, int n) {
int answer = 0;
for(int i=0; i<array.size(); i++){
if(array[i] == n) answer++;
}
return answer;
}
- 머쓱이보다 키 큰 사람
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> array, int height) {
int answer = 0;
for(int i=0; i<array.size(); i++){
if(height < array[i]) answer++;
}
return answer;
}
반응형
'코딩테스트 > 프로그래머스 - LV 0' 카테고리의 다른 글
[프로그래머스] 문자열, 사칙연산, 시뮬레이션, 2차원 배열 (0) | 2024.01.19 |
---|---|
[프로그래머스] 수학, 시뮬레이션, 문자열, 사칙연산 (0) | 2024.01.16 |
[프로그래머스] 문자열, 수학, 조건문, 정렬 (1) | 2024.01.13 |
[프로그래머스] 문자열, 수학, 조건문, 배열, 사칙연산 (0) | 2024.01.12 |
[프로그래머스] 문자열, 수학, 배열, 조건문 (0) | 2024.01.12 |