fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C/C++.
  5. Code, Compile, Run and Debug online from anywhere in world.
  6.  
  7. *******************************************************************************/
  8. #include <iostream>
  9. #include <bits/stdc++.h>
  10. using namespace std;
  11.  
  12. vector < vector < int > > finalVec;
  13.  
  14. void printArray(int p[], int n)
  15. {
  16. vector < int > vec;
  17. for (int i = 0; i < n; i++)
  18. vec.push_back(p[i]);
  19. finalVec.push_back(vec);
  20. return;
  21. }
  22.  
  23. void printAllUniqueParts(int n)
  24. {
  25. int p[n]; // An array to store a partition
  26. int k = 0; // Index of last element in a partition
  27. p[k] = n; // Initialize first partition as number itself
  28.  
  29. // This loop first prints current partition, then generates next
  30. // partition. The loop stops when the current partition has all 1s
  31. while (true)
  32. {
  33. // print current partition
  34. printArray(p, k+1);
  35.  
  36. // Generate next partition
  37.  
  38. // Find the rightmost non-one value in p[]. Also, update the
  39. // rem_val so that we know how much value can be accommodated
  40. int rem_val = 0;
  41. while (k >= 0 && p[k] == 1)
  42. {
  43. rem_val += p[k];
  44. k--;
  45. }
  46.  
  47. // if k < 0, all the values are 1 so there are no more partitions
  48. if (k < 0) return;
  49.  
  50. // Decrease the p[k] found above and adjust the rem_val
  51. p[k]--;
  52. rem_val++;
  53.  
  54.  
  55. // If rem_val is more, then the sorted order is violeted. Divide
  56. // rem_val in differnt values of size p[k] and copy these values at
  57. // different positions after p[k]
  58. while (rem_val > p[k])
  59. {
  60. p[k+1] = p[k];
  61. rem_val = rem_val - p[k];
  62. k++;
  63. }
  64.  
  65. // Copy rem_val to next position and increment position
  66. p[k+1] = rem_val;
  67. k++;
  68. }
  69. }
  70.  
  71.  
  72. int main()
  73.  
  74. {
  75.  
  76. float mile = 1.609344f;
  77.  
  78. float val = 20.0f * mile;
  79.  
  80. for (int i = 0; i < 50; i++) {
  81.  
  82. val += 2.0f * mile;
  83.  
  84. printf("%i\n", (int)(val / 2.0f / mile) * 2);
  85.  
  86. }
  87.  
  88. for (int i = 0; i < 50; i++) {
  89.  
  90. val -= 2.0f * mile;
  91.  
  92. printf("%i\n", (int)(val / 2.0f / mile) * 2);
  93.  
  94. }
  95.  
  96.  
  97.  
  98. return 0;
  99.  
  100. }
Success #stdin #stdout 0s 5292KB
stdin
45
stdout
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
102
104
106
108
110
112
114
116
118
120
118
116
114
112
110
108
106
104
102
100
98
96
94
92
90
88
86
84
82
80
78
76
74
72
70
68
66
64
62
60
58
56
54
52
50
48
46
44
42
40
38
36
34
32
30
26
24
22
20
18