#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
[B]void rotate90(string a, string b, string c, string d)
{
string temp = a;
a = b;
b = c;
c = d;
d = temp;
}
[/B]
int calc_occ (vector<vector<string> >a, vector<vector<string>> p )
{
int a_rows = a.size( );
int a_cols = a[0].size( );
int p_rows = p.size( );
int p_cols = p[0].size( );
int counter=0;
bool flag=false;
int x=0; int y=0;
int i=0; int j=0;
while (a_cols!= i+x && p_cols!= j+y)
{
for (int i=0; i<p_rows; i++){
for (int j=0; j<p_cols; j++)
{
if (a[x+i][y+j]==p[i][j])
flag = true;
if (flag = false){x++; y++; break;} //outer loop increment x until rows then x=0 then y until last dimention
}
if (flag == true) {counter++; x= + p_rows; y= + p_cols; }
}
}
return counter;
}
int main ( ) {
ifstream infile1;
ifstream infile2;
infile1.open ("Array.txt");
infile2.open ("Pattern.txt");
if (!infile1||!infile2) {cout<<"error"; return -1;}
int arr_col, arr_row, pat_col, pat_row;
cout<<"Enter number of rows in your file (array)"<<endl;
cin>> arr_row;
cout<<"Enter Number of columns in your file (array)"<<endl;
cin>> arr_col;
string line; string word;
vector<vector<string> > a;
while(!infile1.eof())
{
getline(infile1, line);
istringstream stringline(line);
vector<string> b;
while(stringline >> word) {
b.push_back(word);
}
a.push_back(b);
}
//output
for (int i = 0; i< arr_row; i++) {
for (int j = 0; j< arr_col; j++) {
cout << a[i][j] << " ";
}
cout << endl;
}
[B]//rotation
for(int i=0; i<arr_row/2; i++)
for(int j=0; j<(arr_col+1)/2; j++)
rotate90(a[i][j], a[arr_row-1-j][i], a[arr_row-1-i][arr_col-1-j], a[j][arr_col-1-i]);
//output of a 90 degree rotation
cout<<"the matrix rotation"<<endl;
for (int i = 0; i<arr_col; i++) {
for (int j = 0; j<arr_row; j++) {
cout << a[i][j] << " ";
}
cout << endl;
}[/B]
cout<<"Enter number of rows in your file (pattern)"<<endl;
cin>> pat_row;
cout<<"Enter Number of columns in your file (pattern)"<<endl;
cin>> pat_col;
vector<vector<string> > p;
while(!infile2.eof())
{
getline(infile2, line);
istringstream stringline(line);
vector<string> c;
while(stringline >> word) {
c.push_back(word);
}
p.push_back(c);
}
for (int i = 0; i< pat_row; i++) { //output of array
for (int j = 0; j< pat_col; j++) {
cout << p[i][j] << " ";
}
cout << endl;
}
}