Bu konuyu okuyanlar

melisa_09

Öğrenci
Katılım
17 Ekim 2017
Mesajlar
9
Reaksiyon puanı
1
Puanları
3
Yaş
53
ödevimin kısa hali ve yazabildiğim kadar kodum aşağıdadır
This program that will gets size and elements of a square matrix which has integer values from 1 to 4. You must get this values from console while we are starting your application.
In your program you will check this matrix if it suits the rules below; 1. One (1) cannot be under two (2). 2. Two (2) cannot be left of three (3). 3. Three (3) cannot be over four (4). 4. Four (4) cannot be right of one (1). You check all the elements in the matrix. If all element is placed according to the rules the program must print “ACCEPTABLE” on the console. Otherwise it will write “NOT MATCH” and writes out the index values (ROW, COLUMN) of first element that is not in right place. Your application will not get any user inputs and don’t use system(“PAUSE”) command to break the execution. Your program must take the input from console and write the results on the screen immediately. After that it will be closed without any activity.

#include <iostream>

using namespace std;

int main(int argc, char * argv[])
{
int m[20][20];
int boyut = atoi(argv[1]);
int deger = atoi(argv[2]);
int d;
d = deger;
int b;
b = (boyut - 1);
int arr[400];
for (int i = 0; i < boyut; i++) {

for (int j = 0; j < boyut; j++) {

while (d > 0) {

d = d % 10;
arr = { d };

m[b - i][b - j] = { d };

if (m[b - i][b - j] == 3)
{
if (m[b - i][b - (j - 1)] == 2) {
cout << "NOT MATCH" << " " << "[" << i << "]" << "[" << j << "]" << "" << endl;
break;
}

}
if (m[b - i][b - j] == 4)
{
if (m[b - i][b - (j - 1)] == 2) {
cout << "NOT MATCH" << " " << "[" << i << "]" << "[" << j << "]" << "" << endl;
break;
}

}
else if (m[b - i][b - j] == 2)
{
if (m[b - (i + 1)][b - j] == 1) {
cout << "NOT MATCH" << " " << "[" << i << "]" << "[" << j << "]" << "" << endl;
break;
}

}
else if (m[b - i][b - j] == 1)
{
if (m[b - i][b - (j + 1)] == 4) {
cout << "NOT MATCH" << " " << "[" << i << "]" << "[" << j << "]" << "" << endl;
break;
}m[(boyut - 1) - i][(boyut - 1) - (j - 1)];

}
else
{
cout << "ACCEPTABLE" << endl;
continue;
}


}


}

}
system("pause");

return 0;
}
 

Son mesajlar

Üst