您的位置:首页 > 产品设计 > UI/UE

UVa_1594Ducci_Sequence

2015-05-27 21:04 274 查看

#include <iostream>

#include <cstdio>

#include <algorithm>

#include <cmath>

using namespace std;

const int n_min = 3;

const int n_max = 15;

int main()

{

bool isZero(int *a, int n);

int Sequene[n_max];

int T_case = 0;

cin >> T_case;

for (int i = 0; i < T_case; i++)

{

int n = 0;

cin >> n;

for (int j = 0; j < n; j++)

{

cin >> Sequene[j];

}

const int loop_max = 1000;

int loop_n = 0;

int flag = 0;

while (loop_n < loop_max)

{

int first_temp = 0;

first_temp = Sequene[0];

for (int i = 0; i<n-1; i++)

{

Sequene[i] = abs(Sequene[i + 1] - Sequene[i]);

}

Sequene[n - 1] = abs(Sequene[n - 1] - first_temp);

if (isZero(Sequene, n))

{

flag = 1;

break;

}

loop_n++;

}

if (flag == 1)

{

cout << "ZERO" << endl;

}

if (flag == 0)

{

cout << "LOOP" << endl;

}

flag = 0;

loop_n = 0;

}

system("pause");

return 0;

}

bool isZero(int *a,int n)

{

for (int i = 0; i < n; i++)

{

if (a[i] != 0)

return false;

}

return true;

}

总结,水题,入门,加油,每日三题!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: