美文网首页
UVA 1594( Ducci Sequence)

UVA 1594( Ducci Sequence)

作者: Gaolex | 来源:发表于2016-05-14 00:00 被阅读251次
    UVA 1594 UVA 1594
    #include <iostream>
    #include <vector>
    #include <cmath>//绝对值函数abs()
    using namespace std;
    
    int main()
    {
        int group;//表示一共几组数据
        int n;//表示接下来输入的数据是几元
        int num;//组数据里面的数字
        cin >> group;
        for (int i = 1; i <= group; i++)
        {
            vector<int> nums;//表示一组数据
            vector <int> tempnums;
            cin >> n;
            for (int j = 1; j <=n ; j++)
            {
                cin >> num;
                nums.push_back(num);
                tempnums.push_back(num);
            }
            for (int k = 0; k < 1000; k++)
            {
                int total = 0;
                for (int j = 0; j< n; j++)
                    total += nums[j];
                if (total == 0)
                {
                    cout << "ZERO\n";
                    break;
                }
                for (int j = 0; j < n; j++)
                {
                    if (j==n-1)
                        tempnums[j] = abs(nums[j] - nums[0]);
                    else
                        tempnums[j] = abs(nums[j] - nums[j+1]);
                }
                for (int j = 0; j < n; j++)
                {
                    nums[j] = tempnums[j];
                }
            }
            int total = 0;
            for (int j = 0; j < n; j++)
                total += nums[j];
            if (total != 0)
            {
                cout << "Loop\n";
            }
        }
        system("pause");
        return 0;
    }
    

    运行结果:

    运行结果

    相关文章

      网友评论

          本文标题:UVA 1594( Ducci Sequence)

          本文链接:https://www.haomeiwen.com/subject/qbymrttx.html