Cod sursa(job #1738519)

Utilizator mariusn01Marius Nicoli mariusn01 Data 6 august 2016 21:19:25
Problema Fractal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <fstream>

using namespace std;

int k, i, j, x, y, sol, n;

int main () {

    ifstream fin ("fractal.in");
    ofstream fout("fractal.out");
    fin>>k>>j>>i;
    k++;
    while (k>1) {
        k--;
        n = (k*k);
        if (i <= k && j<=k) {
            x = j;
            y = k-i+1;
            y = k-y+1;
            i = x;
            j = y;
        } else
            if (i <= k && j > k) {
                j-=k;
                x = k-j+1;
                y = i;
                y = k-y+1;
                i = x;
                j = y;
                sol += (n) * 3;
            } else
                if (i>k && j<=k) {
                    i -= k;
                    sol += n;
                } else {
                    i -= k;
                    j -= k;
                    sol += 2*n;
                }

    }
    fout<<sol;
    return 0;
}