백준 20528 c++

magicdrill·2024년 3월 6일
0

백준 문제풀이

목록 보기
104/655

백준 20528 c++

조건이 쓸데없이 중복되는거 같다... 다시 해봐야 겠다.

#include <iostream>
#include <vector>

using namespace std;

void input_string(vector <string> &testcase)
{
	int i;
	int test;
	string temp;

	cin >> test;
	for (i = 0; i < test; i++)
	{
		cin >> temp;
		testcase.push_back(temp);
	}

	return;
}

int find_answer(vector <string> testcase)
{
	int i;
	int result = 0;

	for (i = 0; i < testcase.size(); i++)
	{
		if (i < testcase.size() - 1)
		{
			if (testcase[i].back() == testcase[i + 1].front() && testcase[i].front() == testcase[i].back())
			{
				result = 1;
			}
			else
			{
				result = 0;
				break;
			}
		}
		else
		{
			if (testcase[i].front() == testcase[i].back())
			{
				result = 1;
			}
			else
			{
				result = 0;
			}
		}
	}

	return result;
}

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

	vector <string> testcase;

	input_string(testcase);
	cout << find_answer(testcase) << "\n";

	return 0;
}

0개의 댓글