#include <stdlib.h>
#include <iostream>
using namespace std;
int block[4][11] = {{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                    { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                    { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                    { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }};
void check_collision( int ball_x, int ball_y )
{
    int reverseX = 0,
        reverseY = 0;
    if( ball_y > 16 ) { // out of range, abort
        cout << endl;
        return;
    }
    switch( ball_x % 10 ) {
        case  7: // check hit left
            if( ball_x != 107 && ball_y < 16 ) {
                if( block[ball_y/4][(ball_x/10)+1] == 1 ) {
                    cout << "line 20 " << "block[" << ball_y/4 << "][" << (ball_x/10)+1 << "]";
                    reverseX = 1;
                }                     
                if( ball_y < 12 && (ball_y % 4 == 2 || ball_y % 4 == 3) &&
                                    block[(ball_y/4)+1][(ball_x/10)+1] == 1 ) {
                    cout << "line 25 " << "block[" << (ball_y/4)+1 << "][" << (ball_x/10)+1 << "]";
                    reverseX = 1;
                }
            }
            break;
        case  0: // check hit right
            if( ball_x != 0 && ball_y < 16 ) {
                if( block[ball_y/4][(ball_x/10)-1] == 1 ) {
                    cout << "line 33 " << "block[" << ball_y/4 << "][" << (ball_x/10)-1 << "]";
                    reverseX = 1;
                }                     
                if( ball_y < 12 && (ball_y % 4 == 2 || ball_y % 4 == 3) &&
                                    block[(ball_y/4)+1][(ball_x/10)-1] == 1 ) {
                    cout << "line 38 " << "block[" << (ball_y/4)+1 << "][" << (ball_x/10)-1 << "]";
                    reverseX = 1;
                }
            }
            break;
        default:
            break;
    }
    switch( ball_y % 4) {
        case 1: // check top hit
            if( ball_y != 13 && block[(ball_y/4)+1][ball_x/10] == 1 ) {
                cout << "line 47 " << "block[" << (ball_y/4)+1 << "][" << ball_x/10 << "]";
                reverseY = 1;
            }
            if( ball_y != 13 && ball_x < 100 && (ball_x % 10 == 8 || ball_x % 10 == 9) &&
                                (block[(ball_y/4)-1][(ball_x/10)+1] == 1 )) {
                cout << "line 52 " << "block[" << (ball_y/4)-1 << "][" << (ball_x/10)+1 << "]";
                reverseY = 1;
            }
            break;
        case 0: // check bottom hit
            if( ball_y != 0 && block[(ball_y/4)-1][ball_x/10] == 1 ) {
                cout << "line 58 " << "block[" << (ball_y/4)-1 << "][" << ball_x/10 << "]";
                reverseY = 1;
            }
            if( ball_y != 0 && ball_x < 100 && (ball_x % 10 == 8 || ball_x % 10 == 9) && 
                               (block[(ball_y/4)-1][(ball_x/10)+1] == 1 )) {
                cout << "line 63 " << "block[" << (ball_y/4)-1 << "][" << (ball_x/10)+1 << "]";
                reverseY = 1;
            }
            break;    
        default:
            break;
    }
    if( reverseX == 1 )
        cout << "X";
    if( reverseY == 1 )
        cout << "Y";
    cout << endl;
}

int main( int argc, char** argv ) {
    for( int y = 0; y < 59; ++y )
        for( int x = 0; x < 107; ++x ) {
            cout << "(" << x << ", " << y << ") ";
            check_collision( x, y );
        }
    cout << endl;
}
/*
void check_collision(void)
{
    int reverseX = 0,
        reverseY = 0;
    if( ball_y > 16 ) // out of range, abort
        return;
    switch( ball_x % 10 ) {
        case  7: // check hit left
            if( ball_x != 107 && ball_y < 16 ) {
                if( block[ball_y/4][(ball_x/10)+1] == 1 ) {
                    block[ball_y/4][(ball_x/10)+1] = 0;
                    reverseX = 1;
                }                     
                if( ball_y < 12 && (ball_y % 4 == 2 || ball_y % 4 == 3) &&
                                    block[(ball_y/4)+1][(ball_x/10)+1] == 1 ) {
                    block[(ball_y/4)+1][(ball_x/10)+1] = 0;
                    reverseX = 1;
                }
            }
            break;
        case  0: // check hit right
            if( ball_x != 0 && ball_y < 16 ) {
                if( block[ball_y/4][(ball_x/10)-1] == 1 ) {
                    block[ball_y/4][(ball_x/10)-1] = 0;
                    reverseX = 1;
                }                     
                if( ball_y < 12 && (ball_y % 4 == 2 || ball_y % 4 == 3) &&
                                    block[(ball_y/4)+1][(ball_x/10)-1] == 1 ) {
                    block[(ball_y/4)+1][(ball_x/10)-1] = 0;
                    reverseX = 1;
                }
            }
            break;
        default:
            break;
    }
    switch( ball_y % 4) {
        case 1: // check top hit
            if( ball_y != 13 && block[(ball_y/4)+1][ball_x/10] == 1 ) {
                block[(ball_y/4)+1][ball_x/10] = 0;
                reverseY = 1;
            }
            if( ball_y != 13 && ball_x < 100 && (ball_x % 10 == 8 || ball_x % 10 == 9) &&
                                (block[(ball_y/4)-1][(ball_x/10)+1] == 1 )) {
                block[(ball_y/4)-1][(ball_x/10)+1] = 0;
                reverseY = 1;
            }
            break;
        case 0: // check bottom hit
            if( ball_y != 0 && block[(ball_y/4)-1][ball_x/10] == 1 ) {
                block[(ball_y/4)-1][ball_x/10] = 0;
                reverseY = 1;
            }
            if( ball_y != 0 && ball_x < 100 && (ball_x % 10 == 8 || ball_x % 10 == 9) && 
                               (block[(ball_y/4)-1][(ball_x/10)+1] == 1 )) {
                block[(ball_y/4)-1][(ball_x/10)+1] = 0;
                reverseY = 1;
            }
            break;    
        default:
            break;
    }
    if( reverseX == 1 )
        right = !right;
    if( reverseY == 1 )
        down = !down;
}
*/
