Advertisement
outoftime

System modeling (c++)

Feb 10th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <numeric>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8.  
  9. void init(int* a, int val) {
  10.     int i = 5;
  11.     while (i > -1) {
  12.         a[i] = val % 10;
  13.         val /= 10;
  14.         --i;
  15.     }
  16. }
  17.  
  18. int check(int* a) {
  19.     return a[0]+a[1]+a[2] == 10 && a[3]+a[4]+a[5] == 10;
  20. }
  21.  
  22. int main() {
  23.     int* a = new int[6];
  24.     int res = 0;
  25.     time_t t = clock();
  26.     for (int i = 0; i < 10e6; ++i) {
  27.         init(a, i);
  28.         res += check(a);
  29.     }
  30.     printf("time: %f\nres: %d", (clock() - t) / CLOCKS_PER_SEC, res);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement