#include
#include
#include
using namespace std;
const int M = 9 + 10;
int a[M][M], t[M];
void err (char c, int n) {
string s = "soooooooooooooooti";
if (c == 'c')
s = "soton ";
if (c == 'r')
s = "satr ";
if (c == 's')
s = "morabaa ";
cout << s << n << " eshkal dare\n";
exit (0);
}
int main () {
for (int i=1; i<10; i++)
for (int j=1; j<10; j++)
cin >> a[i][j];
//satr
for (int i=1; i<10; i++) {
memset (t, 0, sizeof(t));
for (int j=1; j<10; j++){
if (t[ a[i][j] ] == 1)
err ('r', i);
t[ a[i][j] ] = 1;
}
}
//soton
for (int j=1; j<10; j++) {
memset (t, 0, sizeof (t));
for (int i=1; i<10; i++) {
if (t[ a[i][j] ] == 1)
err ('c', j);
t[ a[i][j] ] = 1;
}
}
char c;
cout << "mikhay morabaha ro ham bebinam? (y/n)\n";
cin >> c;
if (c == 'y') {
for (int x=1; x<10; x += 3)
for (int y=1; y<10; y +=3) {
memset (t, 0, sizeof (t));
for (int i=x; i < x+3; i++)
for (int j=y; j < y+3; j++) {
if (t[ a[i][j] ] == 1)
err('s', x*10 + y);
t[ a[i][j] ] = 1;
}
}
}
return 0;
}
Algorithm
#include
#include
#include
using namespace std;
const int M = 9 + 10;
int a[M][M], t[M];
void err (char c, int n) {
string s = "soooooooooooooooti";
if (c == 'c')
s = "soton ";
if (c == 'r')
s = "satr ";
if (c == 's')
s = "morabaa ";
cout << s << n << " eshkal dare\n";
exit (0);
}
int main () {
for (int i=1; i<10; i++)
for (int j=1; j<10; j++)
cin >> a[i][j];
//satr
for (int i=1; i<10; i++) {
memset (t, 0, sizeof(t));
for (int j=1; j<10; j++){
if (t[ a[i][j] ] == 1)
err ('r', i);
t[ a[i][j] ] = 1;
}
}
//soton
for (int j=1; j<10; j++) {
memset (t, 0, sizeof (t));
for (int i=1; i<10; i++) {
if (t[ a[i][j] ] == 1)
err ('c', j);
t[ a[i][j] ] = 1;
}
}
char c;
cout << "mikhay morabaha ro ham bebinam? (y/n)\n";
cin >> c;
if (c == 'y') {
for (int x=1; x<10; x += 3)
for (int y=1; y<10; y +=3) {
memset (t, 0, sizeof (t));
for (int i=x; i < x+3; i++)
for (int j=y; j < y+3; j++) {
if (t[ a[i][j] ] == 1)
err('s', x*10 + y);
t[ a[i][j] ] = 1;
}
}
}
return 0;
}
#include
#include
#include
using namespace std;
const int M = 9 + 10;
int a[M][M], t[M];
void err (char c, int n) {
string s = "soooooooooooooooti";
if (c == 'c')
s = "soton ";
if (c == 'r')
s = "satr ";
if (c == 's')
s = "morabaa ";
cout << s << n << " eshkal dare\n";
exit (0);
}
int main () {
for (int i=1; i<10; i++)
for (int j=1; j<10; j++)
cin >> a[i][j];
//satr
for (int i=1; i<10; i++) {
memset (t, 0, sizeof(t));
for (int j=1; j<10; j++){
if (t[ a[i][j] ] == 1)
err ('r', i);
t[ a[i][j] ] = 1;
}
}
//soton
for (int j=1; j<10; j++) {
memset (t, 0, sizeof (t));
for (int i=1; i<10; i++) {
if (t[ a[i][j] ] == 1)
err ('c', j);
t[ a[i][j] ] = 1;
}
}
char c;
cout << "mikhay morabaha ro ham bebinam? (y/n)\n";
cin >> c;
if (c == 'y') {
for (int x=1; x<10; x += 3)
for (int y=1; y<10; y +=3) {
memset (t, 0, sizeof (t));
for (int i=x; i < x+3; i++)
for (int j=y; j < y+3; j++) {
if (t[ a[i][j] ] == 1)
err('s', x*10 + y);
t[ a[i][j] ] = 1;
}
}
}
return 0;
}
To download the exe file code
Click Downloads
IF you have comments or ideas leave them below