Ducci Sequence UVA - 1594

版权声明:欢迎转载!拒绝抄袭. https://blog.csdn.net/qq_36257146/article/details/87360717
#include <iostream>
#include <bits/stdc++.h>
#define maxn 17
using namespace std;
int a[maxn];
int b[maxn];
int n;

void test()
{
    for(int i = 1; i<=n; i++)
    {
        if(i == n)
            b[i] = abs(a[i]-a[1]);
        else
            b[i] = abs(a[i]-a[i+1]);
        //cout<<a[i]<<" ";
    }
    //cout<<endl;
    for(int i = 1;i<=n;i++)
        a[i] = b[i];
}

int zero()
{
    int flag = 0;
    for(int i = 1; i<=n; i++)
    {
        if(a[i]!=0)
        {
            flag = 1;
            break;
        }
    }
    return !flag;
}

int main()
{
    int c;

    cin>>c;
    while(c--)
    {
        cin>>n;
        for(int i = 1; i<=n; i++)
        {
            cin>>a[i];
        }
        //test
        int chance = 1000;
        while(chance--)
        {
            test();
            if(zero())
            {
                cout<<"ZERO"<<endl;
                break;
            }
        }
        if(chance==-1) cout<<"LOOP"<<endl;
    }
    return 0;
}
/**
4
4
8 11 2 7
5
4 2 0 2 0
7
0 0 0 0 0 0 0
6
1 2 3 1 2 3
**/

猜你喜欢

转载自blog.csdn.net/qq_36257146/article/details/87360717