ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1319. Hotel

what the first test?
Posted by ejjjik 29 Dec 2011 13:25
#include <iostream>
#include <iomanip>
//#include <conio.h>

using namespace std;

#define size 105

int main()
{
    //const int size = 105;
    int mas[size][size];

    int xSize;
    cout << "Input array size: ";
    cin >> xSize;

    if ( xSize <= 100 && xSize >=1 )
    {

    //заполняемые элементы
    int ch = 1;

    // правая половина + диагональ; top right corner + main diagonal
    for ( int f = 0; f < xSize; f++ )
    {

        for( int i = 0, j = xSize - 1, d = f; d >= 0; i++, d-- )
        {
            mas[ i ][ j - d ] = ch++;
        }

    }

    // левая половина; left down corner
    for ( int f = 1; f < xSize; f++ )
    {

        for( int i = f, j = 0, d = 0; i < xSize; i++, d++ )
        {
            mas[ i ][ j + d ] = ch++;
        }

    }

    //output array
    for ( int i = 0; i < xSize; i++ )
    {
        for ( int j = 0; j < xSize; j++ )
        {
        cout << setw(4) << mas[i][j];
        }
        cout << endl;

    }

    }
    //_getch();
   return 0;
}