MaxObznyi

fib_test

Apr 11th, 2021 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. namespace OboznyiMaksymFibTest
  7. {
  8. string header = "<html> \n"
  9. " <head> \n"
  10. " <title>Lab about random generator</title>\n"
  11. " </head> \n"
  12. " <body> \n"
  13. " <h1>by Maksym Oboznyi, K-16, 09.04.2021</h1> \n";
  14.  
  15. string footer = " </body> \n"
  16. "</html>\n";
  17.  
  18. string table_header = " <center>\n"
  19. " <h1> RESULT </h1>\n"
  20. " <table border=\"0\">\n";
  21.  
  22.  
  23. string table_footer = " </table>\n"
  24. " </center>\n";
  25.  
  26. int ITERATIONS;
  27. int MOD, dim, cnt[101][101], cnt1[101];
  28.  
  29. void gen()
  30. {
  31. int f0 = 1, f1 = 1;
  32. for (int i = 0; i < ITERATIONS; i++)
  33. {
  34. cnt[f0][f1]++;
  35. cnt1[f0]++;
  36. f1 = f1 + f0;
  37. f0 = f1 - f0;
  38. f1 %= MOD;
  39. }
  40. }
  41.  
  42. void print2()
  43. {
  44.  
  45. ofstream cout("output.html");
  46. cout << header << table_header;
  47.  
  48. int mx = 0;
  49. for (int i = 0; i < MOD; i++)
  50. for (int j = 0; j < MOD; j++)
  51. mx = max(mx, cnt[i][j]);
  52. cout << " <tr>\n";
  53. cout << " <td style = \"font-size: 24px;\"></td>\n";
  54. for (int i = 0; i < MOD; i++)
  55. cout << " <td style = \"font-size: 24px;\">" << dec << i << "</td>\n";
  56. cout << " </tr>\n";
  57.  
  58. for (int i = 0; i < MOD; i++)
  59. {
  60. cout << " <tr>\n";
  61. cout << " <td style = \"font-size: 24px;\">" << dec << i << "</td>\n";
  62. for (int j = 0; j < MOD; j++)
  63. {
  64. int color = 0xFF * cnt[i][j] / mx;
  65. cout << " <td style = \"font-size: 24px; color: white\"bgcolor=\"" << hex << color << "0000\">" << dec << cnt[i][j] << "</td>\n";
  66. }
  67. cout << " </tr>\n";
  68. }
  69. cout << table_footer << footer;
  70.  
  71. }
  72.  
  73. void print1()
  74. {
  75. ofstream cout("output.html");
  76. cout << header << table_header;
  77. int mx = 0;
  78. for (int i = 0; i < MOD; i++)
  79. mx = max(mx, cnt1[i]);
  80.  
  81. cout << " <tr>\n";
  82. for (int i = 0; i < MOD; i++)
  83. cout << " <td style = \"font-size: 24px;\">" << dec << i << "</td>\n";
  84. cout << " </tr>\n";
  85.  
  86. cout << " <tr>\n";
  87. for (int i = 0; i < MOD; i++)
  88. {
  89. int color = 0xFF * cnt1[i] / mx;
  90. cout << " <td style = \"font-size: 24px; color: white\"bgcolor=\"" << hex << color << "0000\">" << dec << cnt1[i] << "</td>\n";
  91. }
  92. cout << " </tr>\n";
  93. cout << table_footer << footer;
  94.  
  95.  
  96. }
  97. void run()
  98. {
  99. ofstream cout("output.html");
  100. while (1)
  101. {
  102. cerr << "Enter the number of iterations: ";
  103. cin >> ITERATIONS;
  104. if (ITERATIONS < 1 || ITERATIONS > 1'000'000)
  105. cerr << "Incorrect parameter for iterations\n";
  106. else
  107. break;
  108. }
  109. while (1)
  110. {
  111. cerr << "Enter modulo: ";
  112. cin >> MOD;
  113. if (MOD > 100)
  114. cerr << "Modulo should be less than 20 \n";
  115. else
  116. break;
  117. }
  118. while (1)
  119. {
  120. cerr << "Enter dimension(1 or 2): ";
  121. cin >> dim;
  122. if (dim != 1 && dim != 2)
  123. cerr << "Incorrect dimension\n";
  124. else
  125. break;
  126. }
  127. gen();
  128. if (dim == 1)
  129. print1();
  130. else
  131. print2();
  132.  
  133. }
  134. }
  135.  
  136. int main(int argc, char **argv, char **envp)
  137. {
  138. OboznyiMaksymFibTest::run();
  139. return 0;
  140. }
  141.  
Add Comment
Please, Sign In to add comment