History Grading Test Case Generator (using boost)


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2.  * grading-testcase.cpp
  3.  *
  4.  * Created on: Jan 26, 2011
  5.  * Author: dirk
  6.  */
  7.  
  8. #include <cstdlib>
  9. #include <iostream>
  10. #include <ctime>
  11. #include <random>
  12. #include <vector>
  13. #include <iterator>
  14.  
  15. #include <boost/random/mersenne_twister.hpp> // for mt19937
  16. #include <boost/random/uniform_int.hpp>
  17. #include <boost/random/variate_generator.hpp>
  18.  
  19. int main(int argc, char **argv) {
  20. int n(0), m(0);
  21. if(argc < 3 || (n=std::atoi(argv[1])) <= 0 || (m=std::atoi(argv[2])) <= 0) {
  22. std::cout << "N = 0 || M = 0, leaving...\n";
  23. return EXIT_FAILURE;
  24. }
  25.  
  26. boost::mt19937 rng(std::time(0));
  27. boost::uniform_int<> uniform_dist(1, n);
  28. boost::variate_generator<boost::mt19937&, boost::uniform_int<> > order_roller(rng, uniform_dist);
  29.  
  30. std::vector<int> events(n, 0);
  31. for(int i = 0; i < n; ++i) events[i] = i+1;
  32.  
  33. std::cout << n << '\n';
  34. for(int i = 0; i <= m; ++i) {
  35. std::random_shuffle(events.begin(), events.end(), order_roller);
  36. std::copy(events.begin(), events.end(), std::ostream_iterator<int>(std::cout, " "));
  37. std::cout << '\n';
  38. }
  39. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.