题目:https://vjudge.net/problem/UVA-1594
思路:直接模拟即可。
代码:
#include <iostream>
#include <string>
#include <sstream>
#include <cstdio>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
bool is_zero(vector<int> &num, int n)
{
for(int i=0; i<n; i++)
{
if(num[i]!=0)
{
return false;
}
}
return true;
}
int main()
{
int T;
cin >> T;
while(T--)
{
int n;
cin >> n;
vector<int> num;
bool flag = false;
for(int i=0; i<n; i++)
{
int t;
cin >> t;
num.push_back(t);
}
for(int i=0; i<1000; i++)
{
int first = num[0];
for(int j=0; j<n-1; j++)
{
num[j] = abs(num[j]-num[j+1]);
}
num[n-1] = abs(num[n-1]-first);
if(is_zero(num, n))
{
printf("ZERO\n");
flag = true;
break;
}
}
if(!flag)
{
printf("LOOP\n");
}
}
return 0;
}