Cod sursă (job #600905)

Utilizator avatar mihneaudroiu Udroiu Mihnea Alexandru mihneaudroiu IP ascuns
Problemă Ruleta1 ( clasa a 6-a ) Compilator cpp-32 | 0,74 kb
Rundă Arhiva de probleme Status evaluat
Dată 27 iun. 2021 13:12:39 Scor 100
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
ifstream in ("ruleta1.in");
ofstream out ("ruleta1.out");
int v[10001];
int main()
{
    int n,r=0,t=0;
    in>>n;
    for(int i=1; i<=n; i++)
    {
        in>>v[i];
    }
    bool c=1;
    while(c==1)
    {
        c=0;
        for(int i=2; i<=n; i++)
            if(v[i-1]!=0 && v[i]>=v[i-1])
            {
                c=1;
                v[i]=v[i]-v[i-1];
            }
        if(v[n]!=0 && v[1]>=v[n])
        {
            c=1;
            v[1]=v[1]-v[n];
        }
        r++;
    }
    for(int i=1; i<=n; i++)
        if(v[i]!=0)
            t++;
    out<<r<<" "<<t;
    return 0;
}