Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- #include <vector>
- #include <algorithm>
- #include <conio.h>
- int main()
- {
- using namespace std;
- cout << "GIVE ME A NUMBER: ";
- int how_many_times; // Ile liczb ma być sprawdzonych
- cin >> how_many_times;
- cout << endl;
- vector<string>stab;
- unsigned long long *numbers = new unsigned long long[how_many_times];
- for (int i = 0; i < how_many_times; i++) //zapisywanie liczb do tablicy
- {
- numbers[i] = i + 1;
- unsigned long long q = 1;
- stab.push_back(to_string(numbers[i] * numbers[i]));
- }
- cout << endl;
- for (int j = 0; j < how_many_times; j++)
- {
- string buff_pow, buff_root;
- buff_pow = to_string(numbers[j] * numbers[j]); //Zamiana na stringi w celu sprawdzenia
- buff_root = to_string(numbers[j]);
- int li = buff_pow.length() - buff_root.length();
- int x = 0;
- while (true)
- {
- string buff_substr;
- if (buff_root.length() + x > stab[j].length()) //Przeszukiwanie liczby za pomocą bufora
- {
- break;
- }
- if (buff_pow.length() == 1)
- {
- buff_substr = buff_pow.substr(x, x + buff_root.length());
- }
- else
- buff_substr = buff_pow.substr(x, x + buff_root.length()-1);
- if (buff_substr == buff_root)
- {
- cout << buff_root << " is a part of " << buff_pow << " (" << buff_root << " ^ 2)" << endl << endl;
- break;
- }
- x++;
- }
- }
- cout << "---------------------------------------------------------------------END";
- delete[] numbers;
- stab.clear();
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement