Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- double solver_square(double arr[], double x[]);
- void test_solver_square() {
- // a*x*x + b*x + c = 0
- double a = -1;
- double b = 3;
- double c = 4;
- double arr[]{a,b,c};
- double sol[2];
- double x;
- solver_square(arr, sol);
- x = sol[0];
- cout << x << " : " << a * x * x + b * x + c << endl;
- x = sol[1];
- cout << x << " : " << a * x * x + b * x + c << endl;
- }
- /// <summary>
- /// Solve square equation
- /// </summary>
- /// <param name="arr">a, b, c</param>
- /// <param name="x">solutions</param>
- /// <returns></returns>
- double solver_square(double arr[], double x[]) {
- double a = arr[0];
- double b = arr[1];
- double c = arr[2];
- double d = b * b - 4 * a * c;
- if (d >= 0) {
- x[0] = (-b - sqrt(d)) / (2 * a);
- x[1] = (-b + sqrt(d)) / (2 * a);
- return 0;
- }
- else
- return 1;
- }
- int counter = 0;
- bool check_pin(int pin) {
- counter++;
- if (counter >= 3) {
- cout << "Unbloced pin" << endl;
- return false;
- }
- return pin == 1234;
- }
- void brutal_force() {
- srand(time(NULL));
- int pin;
- while (true) {
- pin = rand() % 10000;
- if (check_pin(pin)) {
- cout << "The safe is opened." << endl;
- cout << "Pin: " << pin << endl;
- cout << "Count: " << counter << endl;
- break;
- }
- }
- }
- const int n = 20;
- char buff[n][n];
- void clear_buff() {
- for (int y = 0; y < n; y++) {
- for (int x = 0; x < n; x++) {
- buff[x][y] = ' ';
- }
- }
- }
- void create_figure(int fig) {
- for (int y = 0; y < n; y++) {
- for (int x = 0; x < n; x++) {
- if ( -(y - n/2) == (x - n/2) ||
- (y - n / 2) == (x - n / 2))
- buff[x][y] = '@';
- }
- }
- }
- void show_figure() {
- for (int y = 0; y < n; y++) {
- for (int x = 0; x < n; x++) {
- cout << buff[x][y] << " ";
- }
- cout << endl;
- }
- }
- int main() {
- //test_solver_square();
- //brutal_force();
- clear_buff();
- create_figure(1);
- show_figure();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement