#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; class Solution { public: int maximumGap(vector& nums); }; int Solution::maximumGap(vector &nums) { return -1; } int main(int argc, char **argv) { vector nums, ncopy; int seed, sz, max; int ans, rv; int i; Solution s; string a1; a1 = "pny"; if ((argc != 2 && argc != 5) || a1.find(argv[1][0]) == string::npos) { fprintf(stderr, "usage: a.out check-solution(y|n|p) [seed nums.size() max(nums[i])+1]\n"); exit(1); } if (argc == 2) { // Read from stdin while (cin >> i) nums.push_back(i); } else { // Otherwise, generate randomly seed = atoi(argv[2]); sz = atoi(argv[3]); max = atoi(argv[4]); srand48(seed); for (i = 0; i < sz; i++) nums.push_back(drand48()*max); } if (argv[1][0] == 'p') { // Optionally print for (i = 0; i < nums.size(); i++) printf("%d ", nums[i]); printf("\n"); } ans = -1; if (argv[1][0] != 'n') { // Generate the slow answer ans = 0; ncopy = nums; sort(ncopy.begin(), ncopy.end()); for (i = 1; i < ncopy.size(); i++) { if (ncopy[i]-ncopy[i-1] > ans) ans = ncopy[i]-ncopy[i-1]; } } rv = s.maximumGap(nums); // Get your answer if (ans == -1) { // Either print, or double-check. printf("%d\n", rv); } else { printf("Slow: %d. Yours: %d. %s\n", ans, rv, (ans == rv) ? "Correct" : "Incorrect" ); } return 0; }