๐๊ณต๋ถ/์ฝ๋ฉํ
์คํธ
ํ๋ก๊ทธ๋๋จธ์ค - x๋งํผ ๊ฐ๊ฒฉ์ด ์๋ n๊ฐ์ ์ซ์, C++
Janger
2021. 11. 21. 16:33
728x90
https://programmers.co.kr/learn/courses/30/lessons/12954
์ฝ๋ฉํ ์คํธ ์ฐ์ต - x๋งํผ ๊ฐ๊ฒฉ์ด ์๋ n๊ฐ์ ์ซ์
ํจ์ solution์ ์ ์ x์ ์์ฐ์ n์ ์ ๋ ฅ ๋ฐ์, x๋ถํฐ ์์ํด x์ฉ ์ฆ๊ฐํ๋ ์ซ์๋ฅผ n๊ฐ ์ง๋๋ ๋ฆฌ์คํธ๋ฅผ ๋ฆฌํดํด์ผ ํฉ๋๋ค. ๋ค์ ์ ํ ์กฐ๊ฑด์ ๋ณด๊ณ , ์กฐ๊ฑด์ ๋ง์กฑํ๋ ํจ์, solution์ ์์ฑํด์ฃผ์ธ์.
programmers.co.kr
#include <string>
#include <vector>
using namespace std;
vector<long long> solution(int x, int n) {
vector<long long> answer;
int count = 0;
for(int i=x; count<n; i+=x){
answer.push_back(i);
count++;
}
return answer;
}
728x90