https://school.programmers.co.kr/learn/courses/30/lessons/147355
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int solution(string t, string p) {
int answer = 0;
// 문자열 p의 크기만큼 쪼개기
int N = t.size();
int M = p.size();
// 7, 3 -> 5
int iter = N-M+1;
vector<string> vec_str;
for(int i=0; i<iter; i++){
string str;
str.resize(M);
int idx = 0;
for(int j=i; j<i+M; j++){
str[idx] = t[j];
idx++;
}
// cout << "str = " << str << endl;
vec_str.push_back(str);
}
// 숫자로 변환
vector<long> vec_num;
for(int i=0; i<vec_str.size(); i++){
long num = stol(vec_str[i]);
vec_num.push_back(num);
cout << vec_num[i] << endl;
}
long p_num = stol(p);
for(int i=0; i<vec_num.size(); i++){
if(p_num >= vec_num[i]){
answer++;
}
}
return answer;
}
long 자료형 오랜만에 써본다.ㅎ
'코딩 테스트 > 프로그래머스 코딩테스트' 카테고리의 다른 글
[프로그래머스] 완주하지 못 한 선수 (0) | 2025.03.09 |
---|---|
[프로그래머스] 바탕화면 정리 (0) | 2025.03.09 |
[프로그래머스] 공원 산책 C++ (0) | 2025.03.08 |
[프로그래머스] 추억 점수 (0) | 2025.03.08 |
과일 장수 (0) | 2024.05.19 |