// cloud.cpp // Word Cloud, MCPC 2014, Problem E // C++ version by Michael Goldwasser #include #include using namespace std; #define PAD 10 // interspace padding #define MIN_C 5 #define MAX_C 1000 #define MAX_W 5000 #define MAX_N 1000 bool DEBUG = false; struct item { int wordlength, count, width, height; }; item box[MAX_N]; int ceil(int num, int denom) { return (num/denom + (num % denom > 0 ? 1 : 0)); } int main(int argv, char** argc) { ifstream fin((argv == 1) ? "cloud.in" : argc[1]); DEBUG = (argv > 2); int trial=0; while (true) { int W,N; fin >> W >> N; if (W == 0) break; if (W > MAX_W) cerr << "ILLEGAL W" << endl; if (N > MAX_N) cerr << "ILLEGAL N" << endl; int maxC = 0; string prev = ""; for (int j=0; j> S >> C; if (C < MIN_C || C > MAX_C) cerr << "ILLEGAL C" << endl; if (S < prev) cerr << "WARNING: NOT ALPHABETIZED" << endl; prev = S; // for style only box[j].wordlength = S.size(); box[j].count = C; maxC = max(maxC, C); } for (int j=0; j W) cerr << "WORD TOO LONG" << endl; if (DEBUG) cout << box[j].height << " x " << box[j].width << endl; } int total = 0; int lineWidth = box[0].width; int lineHeight = box[0].height; for (int j=1; j