#include #include using namespace std; //#define DEBUG_OUTPUT const char* INPUT_FILE_NAME = "barcode.in"; const char* OUTPUT_FILE_NAME = "barcode.out"; const int MAX_BARCODE_SIZE = 1000; int barcodeHeight, barcodeWidth; char barcode[MAX_BARCODE_SIZE][MAX_BARCODE_SIZE]; void readInput() { ifstream finp(INPUT_FILE_NAME); finp >> barcodeHeight >> barcodeWidth; for (int x = 0; x < barcodeHeight; ++x) for (int y = 0; y < barcodeWidth; ++y) finp >> barcode[x][y]; #ifdef DEBUG_OUTPUT cout << barcodeHeight << " " << barcodeWidth << endl; for (int x = 0; x < barcodeHeight; ++x) { for (int y = 0; y < barcodeWidth; ++y) cout << barcode[x][y]; cout << endl; } #endif } bool isValid() { for (int y = 0; y < barcodeWidth; ++y) { char first = barcode[0][y]; int x; for (x = 0; x < barcodeHeight - 1; ++x) { if (barcode[x][y] != '.' && barcode[x][y] != '#') return false; if (barcode[x][y] != first) return false; } if (barcode[x][y] < '1' || barcode[x][y] > '9') return false; } return true; } void writeOutput(bool isValid) { ofstream fout(OUTPUT_FILE_NAME); fout << (isValid ? "BUY" : "NO") << endl; #ifdef DEBUG_OUTPUT cout << (isValid ? "BUY" : "NO") << endl; #endif } int main() { readInput(); bool valid = isValid(); writeOutput(valid); return 0; }