Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- string find_num(vector<vector<int>> mas, int num) {
- if (mas.size() == 1) {
- if (num == mas[0][0]) {
- return "yes";
- }
- else {
- return "no";
- }
- }
- int new_n = mas.size() / 2;
- int minus_1 = 0;
- if (mas.size() % 2 == 1) {
- minus_1 = -1;
- }
- while ((new_n + 1) != mas.size() && (new_n - 1) != 0) {
- if (mas[new_n + 1][new_n + 1] > num && mas[new_n][new_n] < num) {
- if (num == mas[new_n + 1][new_n] || num == mas[new_n][new_n + 1]) {
- return "yes";
- }
- else {
- return "no";
- }
- }
- else if (mas[new_n - 1][new_n - 1] < num && mas[new_n][new_n] > num) {
- if (num == mas[new_n - 1][new_n] || num == mas[new_n][new_n - 1]) {
- return "yes";
- }
- else {
- return "no";
- }
- }
- else {
- new_n = new_n + (mas.size() - new_n) / 2;
- }
- }
- int s = mas.size() - 1;
- if (mas[0][0] == num || mas[0][1] == num || mas[1][1] == num || mas[1][0] == num
- || mas[s][s] == num || mas[s][s - 1] == num || mas[s - 1][s] == num || mas[s - 1][s - 1] == num) {
- return "yes";
- }
- else {
- return "no";
- }
- }
- int main() {
- int n;
- cin >> n;
- vector<vector<int>> mas(n, vector<int>(n));
- for (auto& v : mas) {
- for (auto& el : v) {
- int element;
- cin >> element;
- el = element;
- }
- }
- int number;
- cin >> number;
- cout << find_num(mas, number) << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment