1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int R = 5;
const int C = 5;
const int R1 = 3;
const int C1 = 3;
int rr = 0, cc = 0, i= 0, control = 0, st_c = 0, st_r = 0, a= 0;
vector<int>vec;
void extract (int mat [R][C]);
void filling (int mat [R1][C1], int value);
void cross_checking (vector<int>container);
int tcopy [3][3];
int main (){
int tmat [5][5] = {{1,2,3,4,4,},
{7,4,5,7,6,},
{4,0,7,9,0,},
{4,5,5,9,0,},
{4,5,9,9,0,},
};
extract(tmat);
fstream file;
file.open("oppose.txt", ios::in | ios::out);
if (file.is_open()){
for(int k= 0; k< 3; k++)
for(int i = 0; i <3; i++)
file<<tcopy[k][i]<<", ";
cout<<"copied to file successfully!";
file.close();
}
}
void extract (int mat [R][C]){
for (int move= 0; move<(R*C); move++)
{ for (; i < R;)
for (int c= 0; c < C; c++)
{ vec.push_back(mat[i][c]) ;}
cross_checking(vec);
i++;
}
}
void cross_checking (vector<int>container){
vector<int>::iterator itr, itr1;
int a , k;
for ( a = 0; a < container.size(); a++)
{ int k = container[a];
for (itr = container.begin(); itr != itr1; ++itr)
{if (*itr!=k){filling (tcopy, *itr);} }
}
}
void filling (int mat [R1][C1], int value)
{
mat[rr][cc] = value;
if (cc < C1) cc++;
else { cc = 0;
if(rr<R1) rr++;}
}
|