백준 11536 c++

magicdrill·2024년 8월 10일
0

백준 문제풀이

목록 보기
413/654

백준 11536 c++

최초 0, 1 인덱스의 문자열의 순서를 기억하고, 그 다음 문자열들의 관계가 기존 순서와 다르면 NEITHER로 종료, 같다면 해당 순서로 계속 진행으로 구현했다.

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void input_data(vector <string>& names)
{
	int N, i;
	string name;

	cin >> N;
	for (i = 0; i < N; i++)
	{
		cin >> name;
		names.push_back(name);
	}

	return;
}

void find_answer(vector<string>& names)
{
	int i;
	int type = 0, current_type;

	if (names[0] < names[1])//오름차순
	{
		type = 1;
	}
	else//내림차순
	{
		type = 2;
	}
	for (i = 2; i < names.size(); i++)
	{
		if (names[i - 1] < names[i])
		{
			current_type = 1;
			if (current_type == type)
			{
				;
			}
			else
			{
				cout << "NEITHER\n";
				return;
			}
		}
		else
		{
			current_type = 2;
			if (current_type == type)
			{
				;
			}
			else
			{
				cout << "NEITHER\n";
				return;
			}
		}
	}
	if (type == 1)
	{
		cout << "INCREASING\n";
	}
	else
	{
		cout << "DECREASING\n";
	}

	return;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	vector<string> names;

	input_data(names);
	find_answer(names);

	return 0;
}

0개의 댓글