Cod sursa(job #2029659)

Utilizator cont_nouCont Nou cont_nou Data 30 septembrie 2017 12:32:58
Problema Tablete Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream fin ("tablete.in");
ofstream fout ("tablete.out");
int main()
{
    int N,K,a[100][100],v,ok,j,y,i,aux;
    fin>>N>>K;
    v=N*N;
    for( i= N; i>=1; i++)
        for( j=N; j>=1; j++)
            a[i][j]=v--;

for( i=1; i<=N; i++)
        if(a[i][K]%2!=0)
        {
            y=1;
            j=1;
            while (ok)
            {
                if(a[y][j]%2==0)
                {
                    aux=a[y][j];
                    a[y][j]=a[i][K];
                    a[i][K]=aux;
                    ok=1;
                }
                else
                {
                    if(y<=N)
                        j++;
                        else
                        {
                            y=1;
                            j=1;
                        }

                }
            }
        }

    for( i=1; i<=N; i++)
    {
        for(j=1; j<=N; j++)
            fout<<a[i][j]<<" ";
        fout<<"\n";
    }
    return 0;
}