I am trying to work on homework. I have tried to run this code multiple different ways. Here is the sitrep from the assignment - Design an algorithm (using pseudocode) that takes in as an input, two 2-D int arrays that are assumed to be 2 black-and-white images: initialImage x, whose dimensions are IxJ, and finalImage y, whose dimensions are IxK. The algorithm will compare x to the y, row-by-row, as defined below. Your algorithm will employ a dynamic programming scheme to compare X to Y identifying the minimal difference between each row.
Because you are working with black-and-white images only, you should assume that each image is a 2-D int array consisting of 2 possible values: 0 or 1, where 0 represents black and 1 represents white. Thus, this 2-D grid of 0 and 1 values comprise a 2-D black-and-white image. Each row of this image is then simply a 1-D int array filled with either 0s or 1s. Therefore, you must define how you will measure the difference between the strings of 0s and 1s in each row.
Remember that you will do the comparison one row in the images at a time.
First, compare X1,* to Y1,. (Here X1, is the first row in image X and Y1,* is the first row in image Y ). Next, compare X2 to Y2... Each one of these comparisons will require the construction of a D (distance) matrix.
In the following example, the first row of X is X1,, and the first row of Y is Y1, = 00110. *Sorry picture wont load but it is two tables. The first is X 1 2 3 4 5 Y 1 2 3 4 5 1 0 0 1 1 0 1 0 0 1 1 0 2 1 1 0 0 1 2 0 1 0 0 1 3 0 0 1 1 1 3 1 0 1 1 1
After the D matrix is completed, the minimum number in the bottom row is the minimal mismatch for this row. You will assign this value to the variable minVali. This number tells how different row X1,* is from row Y1,* . You will then repeat this comparison for all rows i and aggregate the difference when complete into variable totalDifference = Si minVali.
As a result, the algorithm will compare the total difference to a threshold value called thresh. If total value is above the threshold, the images are declared different; otherwise, they are declared to be similar images. You can assume that the thresh variable is supplied as an input to your algorithm.
// C++ implementation to find the uncommon
// characters of the two strings
#include <bits/stdc++.h>
using namespace std;
// size of the hash table
const int MAX_CHAR = 30;
// function to find the uncommon characters
// of the 6 strings
void findAndPrintUncommonChars(string str1, string str2, string str3, string str4, string str5, string str6)
{
// mark presence of each character as 0
// in the hash table 'present[]'
int present[MAX_CHAR];
for (int i=0; i<MAX_CHAR; i++)
present[i] = 0;
int l1 = str1.size();
int l2 = str2.size();
int l3 = str3.size();
int l4 = str4.size();
int l5 = str5.size();
int l6 = str6.size();
// for each character of str, mark its
// presence as 1 in 'present[]'
for (int i=0; i<l1; i++)
present[str1[i] - 'a'] = 1;
for (int i=0; i<l1; i++)
present[str2[i] - 'a'] = 1;
for (int i=0; i<l1; i++)
present[str3[i] - 'a'] = 1;
// for each character of str
for (int i=0; i<l4; i++)
for (int i=0; i<l5; i++)
for (int i=0; i<l6; i++)
{
// if a character of str2 is also present
// in str1, then mark its presence as -1
if (present[str4[i] - 'a'] == 1
|| present[str4[i] - 'a'] == -1)
present[str4[i] - 'a'] = -1;
else
present[str4[i] - 'a'] = 2;
if (present[str5[i] - 'a'] == 1
|| present[str5[i] - 'a'] == -1)
present[str5[i] - 'a'] = -1;
else
present[str5[i] - 'a'] = 2;
if (present[str6[i] - 'a'] == 1
|| present[str6[i] - 'a'] == -1)
present[str6[i] - 'a'] = -1;
else
present[str6[i] - 'a'] = 2;
}
// print all the uncommon characters
for (int i=0; i<MAX_CHAR; i++)
if (present[i] == 1 || present[i] == 2 )
cout << (char(i + 'a')) << " ";
}
// Driver program to test above
int main()
{
string str1 = {0, 0, 1, 0, 0};
string str2 = {1, 1, 0, 0, 1};
string str3 = {0, 0, 1, 1, 1};
string str4 = {0, 0, 1, 1, 0};
string str5 = {0, 1, 0, 0, 1};
string str6 = {1, 0, 1, 1, 1};
findAndPrintUncommonChars(str1, str4)
findAndPrintUncommonChars(str2, str5)
findAndPrintUncommonChars(str3, str6)
return 1;
}