본문 바로가기

UCPC

[20/07/05] C. 두찌 수열 (8922)

입력값이 작아서 완전탐색으로 풀 수 있는 문제였다. 그대로 값을 입력받아서 두치 수열을 구하는 데 1000번을 넘어가면 loop를 출력하고 배열이 0이 되면 zero를 출력한다.

 

 

int main() {
    vector<int> a(10);
    vector<int> b(10);

    for (int i = 0; i < 10; i++)
    {
    	a[i] = i;
    	b[i] = i;
    }

    if (a == b)
    	cout << "같다!\n";
   	else
   		cout << "다르다\n";
    
    return 0;
}

 

a == b로 벡터 배열이 같은지 확인할 수 있는지 궁금해서 코드를 짜보았다. a == b로 같은지 확인할 수 있는 것 같다.

 

 

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define xx first
#define yy second
 
using namespace std;
using i64 = long long;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

void solve()
{
	int n;
	scanf("%d", &n);

	vector<int> raw(n);
	vector<int> du(n);
	vector<int> zero(n, 0);


	for (int i = 0; i < n; i++)
	{
		scanf("%d", &raw[i]);
		du[i] = raw[i];
	}

	for (int i = 0; i < 1000; i++)
	{
	    int first = du[0];
		for (int i = 0; i < n-1; i++)
		{
			du[i] = abs(du[i] - du[i+1]);
		}
		du[n-1] = abs(du[n-1] - first);

		if (du == zero)
		{
			printf("ZERO\n");
			return ;
		}
	}

	printf("LOOP\n");
	return ;
}

int main() {
    int t;
    scanf("%d", &t);

    for (int i = 0; i < t; i++)
    	solve();
    
    return 0;
}