Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- string grid[3][3];
- int numbers[3][3];
- string S;
- int a;
- void fillIn()
- {
- for (int t{ 0 }; t < 2; t++)
- {
- // Fills rows
- for (int i{ 0 }; i < 3; i++)
- {
- int xcount = 0;
- for (int j{ 0 }; j < 3; j++)
- {
- if (grid[i][j] == "X")
- {
- a = j;
- xcount++;
- }
- }
- if (xcount == 1)
- {
- if (a == 0)
- {
- numbers[i][a] = numbers[i][a + 1] - (numbers[i][a + 2] - numbers[i][a + 1]);
- }
- if (a == 1)
- {
- numbers[i][a] = numbers[i][a + 1] - ((numbers[i][a + 1] - numbers[i][a - 1]) / 2);
- }
- if (a == 2)
- {
- numbers[i][a] = numbers[i][a - 1] + (numbers[i][a - 1] - numbers[i][a - 2]);
- }
- grid[i][a] = "Done";
- }
- }
- // Fills columns
- for (int i{ 0 }; i < 3; i++)
- {
- int xcount = 0;
- int a;
- for (int j{ 0 }; j < 3; j++)
- {
- if (grid[j][i] == "X")
- {
- a = j;
- xcount++;
- }
- }
- if (xcount == 1)
- {
- if (a == 0)
- {
- numbers[a][i] = numbers[a + 1][i] - (numbers[a + 2][i] - numbers[a + 1][i]);
- }
- if (a == 1)
- {
- numbers[a][i] = numbers[a + 1][i] - ((numbers[a + 1][i] - numbers[a - 1][i]) / 2);
- }
- if (a == 2)
- {
- numbers[a][i] = numbers[a - 1][i] + (numbers[a - 1][i] - numbers[a - 2][i]);
- }
- grid[a][i] = "Done";
- }
- }
- }
- }
- void fillLine(int line)
- {
- int xcount{ 0 };
- int lone;
- for (int i{ 0 }; i < 3; i++)
- {
- if (grid[line][i] == "X") xcount++;
- else lone = i;
- }
- if (xcount == 2)
- {
- for (int i{ 0 }; i < 3; i++)
- {
- numbers[line][i] = numbers[1][lone];
- grid[line][i] = "Done";
- }
- }
- if (xcount == 3)
- {
- for (int i{ 0 }; i < 3; i++)
- {
- numbers[line][i] = 0;
- grid[line][i] = "Done";
- }
- }
- }
- int main()
- {
- for (int i{ 0 }; i < 3; i++)
- {
- for (int j{ 0 }; j < 3; j++)
- {
- cin >> S;
- grid[i][j] = S;
- if (S != "X")
- {
- numbers[i][j] = stoi(S, nullptr);
- }
- }
- }
- fillIn();
- fillLine(1);
- fillIn();
- fillLine(0);
- fillIn();
- for (int i{ 0 }; i < 3; i++)
- {
- for (int j{ 0 }; j < 3; j++)
- {
- cout << numbers[i][j] << " ";
- }
- cout << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement