Cod sursa(job #256711)

Utilizator AstronothingIulia Comsa Astronothing Data 12 februarie 2009 01:11:44
Problema Tablete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>

using namespace std;

int main()
{
    ifstream f("tablete.in");
    ofstream f2("tablete.out");

    int n,k;

    f>>n>>k;

    int cnt=0, aux=0;

    for(int i=1;i<=n*(n-1)-1;i++)
    {
        if(i%n==k && (cnt+1)%2)
            {aux=++cnt; f2<<++cnt<<" ";}
        else if(i%n==1 && aux)
            {f2<<aux<<" ";aux=0;}
        else
            f2<<++cnt<<" ";
        if(!(i%n))
            f2<<"\n";
    }

    if( (n*n-(n-k))%2 )
    {
        f2<<n*n<<"\n";
        //cnt++;
    }

    else f2<<++cnt<<"\n";

    if(aux) f2<<aux<<" ";
    else f2<<++cnt<<" ";

    for(int i=1;i<n;i++) f2<<++cnt<<" ";


    f.close();
    f2.close();
    return 0;
}