Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.14 KB | None | 0 0
  1. #line 2 "Straights.cpp"
  2.  
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5.  
  6. #define FOR(i, a, b)             for(__typeof(b) i = a; i <= b; i++)
  7. #define REP(i, a)                 for(__typeof(a) i = 0; i < a; i++)
  8. #define REPN(i, a)               for(__typeof(a) i = 1; i <= a; i++)
  9. #define ITERATE(it, v)          for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
  10. #define D(x)                        cout << #x << " = " << (x) << endl
  11. #define bitcount                 __builtin_popcount
  12. #define oo                          (INT_MAX / 2)
  13. #define pb                         push_back
  14. #define mp                        make_pair
  15. #define gcd                       __gcd
  16.  
  17. typedef long long LL;
  18. typedef pair <int, int> pii;
  19.  
  20.  
  21. class Straights {
  22. public:
  23.     int howMany( vector <int> hand, int k ) {
  24.         int ret = 0;
  25.         for (int i = 0; i < hand.size() - k + 1; i ++) {
  26.             int m = 1;
  27.             for (int j = 0; j < k; j ++) {
  28.                 m = (m * hand[i + j]);
  29.             }
  30.             ret += m;
  31.         }
  32.         return ret;
  33.     }
  34. };
  35.  
  36. // BEGIN CUT HERE
  37. #include <cstdio>
  38. #include <ctime>
  39. #include <iostream>
  40. #include <string>
  41. #include <vector>
  42. namespace moj_harness {
  43.     using std::string;
  44.     using std::vector;
  45.     int run_test_case(int);
  46.     void run_test(int casenum = -1, bool quiet = false) {
  47.         if (casenum != -1) {
  48.             if (run_test_case(casenum) == -1 && !quiet) {
  49.                 std::cerr << "Illegal input! Test case " << casenum << " does not exist." << std::endl;
  50.             }
  51.             return;
  52.         }
  53.  
  54.         int correct = 0, total = 0;
  55.         for (int i=0;; ++i) {
  56.             int x = run_test_case(i);
  57.             if (x == -1) {
  58.                 if (i >= 100) break;
  59.                 continue;
  60.             }
  61.             correct += x;
  62.             ++total;
  63.         }
  64.  
  65.         if (total == 0) {
  66.             std::cerr << "No test cases run." << std::endl;
  67.         } else if (correct < total) {
  68.             std::cerr << "Some cases FAILED (passed " << correct << " of " << total << ")." << std::endl;
  69.         } else {
  70.             std::cerr << "All " << total << " tests passed!" << std::endl;
  71.         }
  72.     }
  73.  
  74.     int verify_case(int casenum, const int &expected, const int &received, std::clock_t elapsed) {
  75.         std::cerr << "Example " << casenum << "... ";
  76.  
  77.         string verdict;
  78.         vector<string> info;
  79.         char buf[100];
  80.  
  81.         if (elapsed > CLOCKS_PER_SEC / 200) {
  82.             std::sprintf(buf, "time %.2fs", elapsed * (1.0/CLOCKS_PER_SEC));
  83.             info.push_back(buf);
  84.         }
  85.  
  86.         if (expected == received) {
  87.             verdict = "PASSED";
  88.         } else {
  89.             verdict = "FAILED";
  90.         }
  91.  
  92.         std::cerr << verdict;
  93.         if (!info.empty()) {
  94.             std::cerr << " (";
  95.             for (size_t i=0; i<info.size(); ++i) {
  96.                 if (i > 0) std::cerr << ", ";
  97.                 std::cerr << info[i];
  98.             }
  99.             std::cerr << ")";
  100.         }
  101.         std::cerr << std::endl;
  102.  
  103.         if (verdict == "FAILED") {
  104.             std::cerr << "    Expected: " << expected << std::endl;
  105.             std::cerr << "    Received: " << received << std::endl;
  106.         }
  107.  
  108.         return verdict == "PASSED";
  109.     }
  110.  
  111.     int run_test_case(int casenum__) {
  112.         switch (casenum__) {
  113.         case 0: {
  114.             int hand[]                = {0,3,1,2,0,0,0,0,0,0,0,0,0};
  115.             int k                     = 2;
  116.             int expected__            = 5;
  117.  
  118.             std::clock_t start__      = std::clock();
  119.             int received__            = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
  120.             return verify_case(casenum__, expected__, received__, clock()-start__);
  121.         }
  122.         case 1: {
  123.             int hand[]                = {1,1,1,1,1,1,1,1,1,1,1,1,1};
  124.             int k                     = 5;
  125.             int expected__            = 9;
  126.  
  127.             std::clock_t start__      = std::clock();
  128.             int received__            = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
  129.             return verify_case(casenum__, expected__, received__, clock()-start__);
  130.         }
  131.         case 2: {
  132.             int hand[]                = {4,4,4,4,4,4,4,4,4,4,4,4,4};
  133.             int k                     = 13;
  134.             int expected__            = 67108864;
  135.  
  136.             std::clock_t start__      = std::clock();
  137.             int received__            = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
  138.             return verify_case(casenum__, expected__, received__, clock()-start__);
  139.         }
  140.         case 3: {
  141.             int hand[]                = {4,0,4,0,4,0,4,0,4,0,4,0,4};
  142.             int k                     = 2;
  143.             int expected__            = 0;
  144.  
  145.             std::clock_t start__      = std::clock();
  146.             int received__            = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
  147.             return verify_case(casenum__, expected__, received__, clock()-start__);
  148.         }
  149.         case 4: {
  150.             int hand[]                = {1,2,3,4,1,2,3,4,1,2,3,4,1};
  151.             int k                     = 1;
  152.             int expected__            = 31;
  153.  
  154.             std::clock_t start__      = std::clock();
  155.             int received__            = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
  156.             return verify_case(casenum__, expected__, received__, clock()-start__);
  157.         }
  158.  
  159.         // custom cases
  160.  
  161. /*      case 5: {
  162.             int hand[]                = ;
  163.             int k                     = ;
  164.             int expected__            = ;
  165.  
  166.             std::clock_t start__      = std::clock();
  167.             int received__            = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
  168.             return verify_case(casenum__, expected__, received__, clock()-start__);
  169.         }*/
  170. /*      case 6: {
  171.             int hand[]                = ;
  172.             int k                     = ;
  173.             int expected__            = ;
  174.  
  175.             std::clock_t start__      = std::clock();
  176.             int received__            = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
  177.             return verify_case(casenum__, expected__, received__, clock()-start__);
  178.         }*/
  179. /*      case 7: {
  180.             int hand[]                = ;
  181.             int k                     = ;
  182.             int expected__            = ;
  183.  
  184.             std::clock_t start__      = std::clock();
  185.             int received__            = Straights().howMany(vector <int>(hand, hand + (sizeof hand / sizeof hand[0])), k);
  186.             return verify_case(casenum__, expected__, received__, clock()-start__);
  187.         }*/
  188.         default:
  189.             return -1;
  190.         }
  191.     }
  192. }
  193.  
  194. #include <cstdlib>
  195. int main(int argc, char *argv[]) {
  196.     if (argc == 1) {
  197.         moj_harness::run_test();
  198.     } else {
  199.         for (int i=1; i<argc; ++i)
  200.             moj_harness::run_test(std::atoi(argv[i]));
  201.     }
  202. }
  203. // END CUT HERE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement