Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- namespace OboznyiMaksymFibTest
- {
- string header = "<html> \n"
- " <head> \n"
- " <title>Lab about random generator</title>\n"
- " </head> \n"
- " <body> \n"
- " <h1>by Maksym Oboznyi, K-16, 09.04.2021</h1> \n";
- string footer = " </body> \n"
- "</html>\n";
- string table_header = " <center>\n"
- " <h1> RESULT </h1>\n"
- " <table border=\"0\">\n";
- string table_footer = " </table>\n"
- " </center>\n";
- int ITERATIONS;
- int MOD, dim, cnt[101][101], cnt1[101];
- void gen()
- {
- int f0 = 1, f1 = 1;
- for (int i = 0; i < ITERATIONS; i++)
- {
- cnt[f0][f1]++;
- cnt1[f0]++;
- f1 = f1 + f0;
- f0 = f1 - f0;
- f1 %= MOD;
- }
- }
- void print2()
- {
- ofstream cout("output.html");
- cout << header << table_header;
- int mx = 0;
- for (int i = 0; i < MOD; i++)
- for (int j = 0; j < MOD; j++)
- mx = max(mx, cnt[i][j]);
- cout << " <tr>\n";
- cout << " <td style = \"font-size: 24px;\"></td>\n";
- for (int i = 0; i < MOD; i++)
- cout << " <td style = \"font-size: 24px;\">" << dec << i << "</td>\n";
- cout << " </tr>\n";
- for (int i = 0; i < MOD; i++)
- {
- cout << " <tr>\n";
- cout << " <td style = \"font-size: 24px;\">" << dec << i << "</td>\n";
- for (int j = 0; j < MOD; j++)
- {
- int color = 0xFF * cnt[i][j] / mx;
- cout << " <td style = \"font-size: 24px; color: white\"bgcolor=\"" << hex << color << "0000\">" << dec << cnt[i][j] << "</td>\n";
- }
- cout << " </tr>\n";
- }
- cout << table_footer << footer;
- }
- void print1()
- {
- ofstream cout("output.html");
- cout << header << table_header;
- int mx = 0;
- for (int i = 0; i < MOD; i++)
- mx = max(mx, cnt1[i]);
- cout << " <tr>\n";
- for (int i = 0; i < MOD; i++)
- cout << " <td style = \"font-size: 24px;\">" << dec << i << "</td>\n";
- cout << " </tr>\n";
- cout << " <tr>\n";
- for (int i = 0; i < MOD; i++)
- {
- int color = 0xFF * cnt1[i] / mx;
- cout << " <td style = \"font-size: 24px; color: white\"bgcolor=\"" << hex << color << "0000\">" << dec << cnt1[i] << "</td>\n";
- }
- cout << " </tr>\n";
- cout << table_footer << footer;
- }
- void run()
- {
- ofstream cout("output.html");
- while (1)
- {
- cerr << "Enter the number of iterations: ";
- cin >> ITERATIONS;
- if (ITERATIONS < 1 || ITERATIONS > 1'000'000)
- cerr << "Incorrect parameter for iterations\n";
- else
- break;
- }
- while (1)
- {
- cerr << "Enter modulo: ";
- cin >> MOD;
- if (MOD > 100)
- cerr << "Modulo should be less than 20 \n";
- else
- break;
- }
- while (1)
- {
- cerr << "Enter dimension(1 or 2): ";
- cin >> dim;
- if (dim != 1 && dim != 2)
- cerr << "Incorrect dimension\n";
- else
- break;
- }
- gen();
- if (dim == 1)
- print1();
- else
- print2();
- }
- }
- int main(int argc, char **argv, char **envp)
- {
- OboznyiMaksymFibTest::run();
- return 0;
- }
Add Comment
Please, Sign In to add comment