입력값이 작아서 완전탐색으로 풀 수 있는 문제였다. 그대로 값을 입력받아서 두치 수열을 구하는 데 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;
}
'UCPC' 카테고리의 다른 글
[20/07/05] J. 비밀이메일 (2999) (0) | 2020.07.09 |
---|---|
[20/07/05] D. 십자가 찾기 (16924) (0) | 2020.07.09 |
[20/07/05] B. 과일서리 (17213) (0) | 2020.07.09 |
[20/07/05] E. 부분수열의 합 (14225) (0) | 2020.07.09 |
[20/05/24] I 모노디지털 표현 (2287) (0) | 2020.05.30 |