코딩공부/Softeer

[Softeer/C++]Level1 위험한 효도

usingsystem 2024. 3. 8. 01:00
728x90

https://softeer.ai/practice/7368

 

Softeer - 현대자동차그룹 SW인재확보플랫폼

 

softeer.ai

소스코드

#include<iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main(int argc, char** argv)
{
	int a,b,d;
	cin >> a>>b>>d;

	int destint = d * 2;
	int curdir =0;
	int time =0;
	int temp = 0;
	bool isFront = false;
	while (destint != curdir)
	{
		if (isFront == false)
		{
			for (int i = 0; i < a; i++)
			{
				time += 1;
				curdir += 1;
				if (destint == curdir)
					break;

				if (d == curdir)
				{
					temp = a;
					a = b;
					b = temp;
					d = destint;

					time += a;
					curdir += a;
					break;
				}
			}
		}
		else {
			time += b;
		}
		isFront = isFront  == true ? false : true;
	}
	cout << time;
	return 0;
}
728x90