코딩공부/Softeer

[Softeer/C++]Level2 8단 변속기

usingsystem 2024. 3. 8. 15:47
728x90

https://softeer.ai/practice/6283/history?questionType=ALGORITHM

 

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

 

softeer.ai

소스코드

#include <string>
#include <iostream>
using namespace std;

int main()
{
	int n;
	int temp = 0;

	string result;
	for (int i = 0; i < 8; i++)
	{
		cin >> n;

		if (temp == 0)
		{
			temp = n;
			continue;
		}

		int min = n - temp;
		if (min == 1)
		{
			if (result == "")
			{
				result = "ascending";
			}

			if (result != "ascending")
			{
				result = "mixed";
				break;
			}

			result = "ascending";
		}
		else if (min == -1)
		{
			if (result == "")
			{
				result = "descending";
			}

			if (result != "descending")
			{
				result = "mixed";
				break;
			}
			result = "descending";
		}
		else {
			result = "mixed";
			break;
		}
		temp = n;
	}
	cout << result;
	return 0;
}
728x90