배열 만들기 2 : 문제 링크
empty() 함수 사용법
str.empty();
v.empty();
- string 또는 vector 객체가 비어있으면 1을, 문자열 또는 원소가 저장되어 있으면 0을 반환
#include <string>
#include <vector>
using namespace std;
vector<int> solution(int l, int r) {
vector<int> answer;
for(int i = l; i <= r; ++i) {
string num = to_string(i);
if(i % 5 == 0) {
int check = 0;
for(int j = 0; j < num.size(); ++j) {
if(num[j] == '0' || num[j] == '5') check = 1;
else {
check = 0;
break;
}
}
if(check) answer.push_back(i);
}
}
if(answer.empty()) answer.push_back(-1);
return answer;
}