Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by dsadsad ( 8 years ago )
#include <iostream>

using namespace std;

int main() {
    FILE *file;
    short int number;
    int raw, col, width, height;
    short int array[1000][1000] = {};
    bool flag;
    short int id = 0;
    int count = 0;

    file = fopen&#40;"data.txt", "r"&#41;;
    for (int i = 0; i < 1259; ++i) {
        fscanf(file, "#%hd @ %d,%d: %dx%d\n", &number, &col, &raw, &width, &height);
        flag = true;
        for (int j = col; j < col + width; ++j) {
            for (int k = raw; k < raw + height; ++k) {
                if (array[j][k] != 0) {
                    flag = false;
                    id = array[j][k];
                    break;
                } else {
                    array[j][k] = number;
                }
            }
            if (!flag) {
                break;
            }
        }
        if (!flag) {
            for (int j = col; j < col + width; ++j) {
                for (int k = raw; k < raw + height; ++k) {
                    array[j][k] = -1;
                }
            }
            for (int j = 0; j < 1000; ++j) {
                for (int k = 0; k < 1000; ++k) {
                    if (array[j][k] == id) {
                        array[j][k] = -1;
                    }
                }
            }
        }
    }
    fclose(file);

    for (int i = 0; i < 1000; ++i) {
        for (int j = 0; j < 1000; ++j) {
            if (array[i][j] != -1 && array[i][j] != 0) {
                cout << array[i][j] << endl;
                count++;
            }
        }
    }

    cout << endl << count << endl;

    return 0;
}

 

Revise this Paste

Parent: 96204
Your Name: Code Language: