728x90
https://softeer.ai/practice/7368
νλ μνν°μ΄ Lv1. μνν ν¨λ C++ νμ΄
μ΄μ©λ€ 보λ ν¨λ μ리μ¦λ§ νΈλμ€μ΄λ€γ γ
μλλ λμ΄λκ° Lv2μλλ° Lv1λ‘ λ΄λ €μ¨ λ―.
μ/λ€λ‘ κ° λ, μμ§μ/μ μ§ν λμ κ²½μ°λ§ μ λλλ©΄ μ½κ² μ±κ³΅ν μ μλ λ¬Έμ μ λλ€!
#include<iostream>
using namespace std;
int main(int argc, char** argv)
{
int a; int b; int d;
cin >> a >> b >> d;
int now = 0;
int time = 0;
int cnt = 0;
bool isCatch = false;
while(1){
cnt ++;
if(!isCatch){
if(cnt%2==1) { // μμΌλ‘ μ΄λ
if(d-now < a) { // μ λμμ κ±°λ¦¬κ° μΌλ§ μ λ¨μμ λ
time += (d-now);
now += (d-now);
} else{
time += a;
now += a;
}
if(d == now) { isCatch = true; cnt = 0; }
} else{ // μ μ§
time += b;
}
}
else{
if(cnt%2==1) { // λλ§κ°κΈ°
if(now < b) { // λμ°©μ§κΉμ§ κ±°λ¦¬κ° μΌλ§ μ λ¨μμ λ
time += now;
now -= now;
} else{
time += b;
now -= b;
}
if(now == 0) break;
} else{ // μ μ§
time += a;
}
}
}
cout << time;
return 0;
}
728x90
'π μκ³ λ¦¬μ¦ > Softeer' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Javascript(NodeJS)/Softeer] Lv1. A+B (0) | 2024.06.27 |
---|---|
[Javascript(NodeJS)/Softeer] Lv1. 근무 μκ° (0) | 2024.06.27 |
[C++/Softeer] Lv3. μμλλ‘ λ°©λ¬ΈνκΈ° (HSAT 7ν μ κΈ° μ½λ© μΈμ¦νκ° κΈ°μΆ) (0) | 2024.06.27 |
[C++/Softeer] Lv2. νμμ€ μμ½ (0) | 2024.06.27 |
[C++/Softeer] Lv3. ν¨κ»νλ ν¨λ (0) | 2024.06.26 |