728x90
ํ๋ก๊ทธ๋๋จธ์ค C++
๋ฐฐ์ด ์๋ฅด๊ธฐ
vector<int> solution(vector<int> numbers, int num1, int num2) {
vector<int> answer;
for(num1; num1<=num2; ++num1){
answer.push_back(numbers[num1]);
}
return answer;
}
์ธ๊ณํ์ฑ์ ๋์ด
string solution(int age) {
string alpha = "abcdefghij";
string answer = "";
int tmp = age;
if(tmp==1000) return "baaa";
if(tmp>99) {
answer.push_back(alpha[age / 100]);
age -= 100*(age/100);
}
if(tmp>9) answer.push_back(alpha[age / 10]);
answer.push_back(alpha[age % 10]);
return answer;
}
→ ์๋ก์ด ํ์ด
string answer = to_string(age);
for(auto& v : answer) v += 'a'-'0';
return answer;
// for(๋ฐ๋ณต๋ ์ง์ญ๋ณ์ : ๋ฐฐ์ด) -> ์ง์ญ๋ณ์๊ฐ ๋ฐฐ์ด ๊ธธ์ด๋งํผ ๋ฐ๋ณต๋จ
// ๊ทผ๋ฐ ์ด ํ์ด ์ดํด๊ฐ ์๋๋ค!!
์ง๋ฃ์์ ์ ํ๊ธฐ
vector<int> solution(vector<int> emergency) {
vector<int> answer;
int seq[10] = {0,};
for(int i=0; i<emergency.size(); ++i){
int max_index = max_element(emergency.begin(), emergency.end()) - emergency.begin();
seq[max_index] = i+1;
emergency[max_index] = 0;
}
for(int i : seq){
if(i!=0) answer.push_back(i);
}
return answer;
}
์์์์ ๊ฐ์
int solution(int n) {
int answer = 0;
for(int i=1; i<=n; ++i){
if(n%i == 0) answer++;
}
return answer;
}
โ๐ป ๋ฐ๋ณต๋ฌธ ์งง๊ฒ ์ฐ๊ธฐ for(๋ฐ๋ณต๋ ์ง์ญ๋ณ์ : ๋ฐฐ์ด) -> ์ง์ญ๋ณ์๊ฐ ๋ฐฐ์ด ๋ด์ฉ ์์๋๋ก ๋ฐ๋ณต๋จ
โ๐ป ๋ฒกํฐ์ ์ต๋๊ฐ → int max = *max_element(v.begin(), v.end()); โ๐ป ๋ฒกํฐ์ ์ต๋๊ฐ์ ๊ฐ์ง ์ธ๋ฑ์ค → int max_index = max_element(v.begin(), v.end()) - v.begin();
728x90
'๐ ์๊ณ ๋ฆฌ์ฆ > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[PGS] Lv.0 (์ฝ๋ฉํ ์คํธ ์ ๋ฌธ) 10์ผ์ฐจ ๋ฌธ์ (0) | 2023.02.20 |
---|---|
[PGS] Lv.0 (์ฝ๋ฉํ ์คํธ ์ ๋ฌธ) 9์ผ์ฐจ ๋ฌธ์ (0) | 2023.01.26 |
[PGS] Lv.0 (์ฝ๋ฉํ ์คํธ ์ ๋ฌธ) 7์ผ์ฐจ ๋ฌธ์ (0) | 2023.01.26 |
[PGS] Lv.1 : ์์ ๋ง๋ค๊ธฐ (0) | 2023.01.16 |
[PGS] Lv.1 : ์์ ๋ํ๊ธฐ (0) | 2023.01.16 |