My homework will create a program that check the numbers in an array with a given pattern. Program must take the matrix dimensions and terms in the matrix as arguments from command line. For example program name is myProg.exe and we want to check a 2x3 dimensioned matrix with (maximum dimension limit is 20x20):
1 2 3
4 5 6
Then I will run your program as.
The program will check a special matrix pattern and prints out ACCEPTABLE or NOT MATCH according to the values we put from the console. The Special Pattern: In a row major representation the cells of the matrix must obey this rule. Some terms of the matrix must be sum or product of the neighbor cells. In row major representation the sum and product operations are placed as given in the examples. Sum and Product cells follows each other with one free cells. For Odd rows the sequence starts with free cells and in Even Rows the sequence starts with Sum or Product cell.
My code is here:
#include <iostream>
#include <sstream>
using namespace std;
static int iter = 0;
static unsigned int sat=3, sut=2;
bool ok = false;
int *accepted;
int *array;
string isAcceptable(int mat[]) {
int l, co = 0;
bool operation = false;
int mat2[sat][sut];
for (int i = 0; i < sat; i++) {
for (int j = 0; j < sut; j++) {
mat2[i][j] = mat[co];
co++;
}
}
for (int i = 0; i < sat; i++) {
if (i % 2 == 0)
l = 1;
else
l = 0;
for (int j = l; j < sut; j += 2) {
int totalProduct;
if (!operation) {
totalProduct = 0;
if (j > 0)
totalProduct += mat2[i][j - 1];
if (j < sut - 1)
totalProduct += mat2[i][j + 1];
if (i > 0)
totalProduct += mat2[i - 1][j];
if (i < sat - 1)
totalProduct += mat2[i + 1][j];
} else {
totalProduct = 1;
if (j > 0)
totalProduct *= mat2[i][j - 1];
if (j < sut - 1)
totalProduct *= mat2[i][j + 1];
if (i > 0)
totalProduct *= mat2[i - 1][j];
if (i < sat - 1)
totalProduct *= mat2[i + 1][j];
}
if (mat2[i][j] != totalProduct)
return "NOT MATCH";
operation = !operation;
}
}
return "ACCEPTABLE";
}
void change(int index1, int index2) {
int temp;
temp = array[index1];
array[index1] = array[index2];
array[index2] = temp;
iter++;
}
void combine(int mat[], int len) {
if(ok)
return;
array = new int[len];
*array = *mat;
if (len <= sat * sut) {
for (int i = len; i < sat * sut - 1; i++) {
for (int j = i; j < sat * sut; j++) {
combine(array, len + 1);
change(i, j);
if (isAcceptable(array) == ("ACCEPTABLE")) {
int accepted[sat*sut];
*accepted = *array;
ok = true;
return;
}
}
}
} else
return;
}
string isAcceptableCombine(int mat[]) {
combine(mat, 6);
if (ok)
{
cout<< " TRUE Sequense";
return "ACCEPTABLE";
}
else
cout<< " FALSE Sequense";
return "NOT MATCH";
}
int main(int argc, char** argv) {
int matris[] = {1,2,1,4,1,6};
isAcceptableCombine(matris);
}
My code's result is always returning TRUE Sequence.
Where is my mistake?
Related
I am trying to understand the implementation of the Rabin-Karp algorithm. d is the number of characters in the input alphabet, but if I replace 0 or any other value instead of 20, it won't affect anything. Why is this happening like this ?
// Rabin-Karp algorithm in C++
#include <string.h>
#include <iostream>
using namespace std;
#define d 20
void rabinKarp(char pattern[], char text[], int q) {
int m = strlen(pattern);
int n = strlen(text);
int i, j;
int p = 0;
int t = 0;
int h = 1;
for (i = 0; i < m - 1; i++)
h = (h * d) % q;
// Calculate hash value for pattern and text
for (i = 0; i < m; i++) {
p = (d * p + pattern[i]) % q;
t = (d * t + text[i]) % q;
}
// Find the match
for (i = 0; i <= n - m; i++) {
if (p == t) {
for (j = 0; j < m; j++) {
if (text[i + j] != pattern[j])
break;
}
if (j == m)
cout << "Pattern is found at position: " << i + 1 << endl;
}
if (i < n - m) {
t = (d * (t - text[i] * h) + text[i + m]) % q;
if (t < 0)
t = (t + q);
}
}
}
int main() {
// char text[] = "ABCCDXAEFGX";
char text[] = "QWERTYUIOPASDFGHJKLXQWERTYUIOPASDFGHJKLX";
char pattern[] = "KLXQW";
int q = 13;
rabinKarp(pattern, text, q);
}
I believe the short answer is that the lower d is the more hash collisions you will have, but you go about verifying the match anyway so it does not affect anything.
A bit more verbose:
First let me modify your code to be have more expressive variables:
// Rabin-Karp algorithm in C++
#include <string.h>
#include <iostream>
using namespace std;
#define HASH_BASE 0
void rabinKarp(char pattern[], char text[], int inputBase) {
int patternLen = strlen(pattern);
int textLen = strlen(text);
int i, j; //predefined iterators
int patternHash = 0;
int textHash = 0;
int patternLenOut = 1;
for (i = 0; i < patternLen - 1; i++)
patternLenOut = (patternLenOut * HASH_BASE) % inputBase; // hash of pattern len
// Calculate hash value for pattern and text
for (i = 0; i < patternLen; i++) {
patternHash = (HASH_BASE * patternHash + pattern[i]) % inputBase;
textHash = (HASH_BASE * textHash + text[i]) % inputBase;
}
// Find the match
for (i = 0; i <= textLen - patternLen; i++) {
if (patternHash == textHash) {
for (j = 0; j < patternLen; j++) {
if (text[i + j] != pattern[j])
break;
}
if (j == patternLen)
cout << "Pattern is found at position: " << i + 1 << endl;
}
if (i < textLen - patternLen) {
textHash = (HASH_BASE * (textHash - text[i] * patternLenOut) + text[i + patternLen]) % inputBase;
if (textHash < 0)
textHash = (textHash + inputBase);
}
}
}
int main() {
// char text[] = "ABCCDXAEFGX";
char text[] = "QWEEERTYUIOPASDFGHJKLXQWERTYUIOPASDFGHJKLX";
char pattern[] = "EE";
int q = 13;
rabinKarp(pattern, text, q);
}
The easiest way to attack it is to set HASH_BASE (previously d) to zero and see where we can simplify. The rabinKarp function can then be reduced to:
void rabinKarp(char pattern[], char text[], int inputBase) {
int patternLen = strlen(pattern);
int textLen = strlen(text);
int i, j; //predefined iterators
int patternHash = 0;
int textHash = 0;
int patternLenOut = 0;
// Calculate hash value for pattern and text
for (i = 0; i < patternLen; i++) {
patternHash = (pattern[i]) % inputBase;
textHash = (text[i]) % inputBase;
}
// Find the match
for (i = 0; i <= textLen - patternLen; i++) {
if (patternHash == textHash) {
for (j = 0; j < patternLen; j++) {
if (text[i + j] != pattern[j])
break;
}
if (j == patternLen)
cout << "Pattern is found at position: " << i + 1 << endl;
}
if (i < textLen - patternLen) {
textHash = (text[i + patternLen]) % inputBase;
if (textHash < 0)
textHash = (textHash + inputBase);
}
}
}
now you'll notice that all the hashes becomes is the sum of the letters mod some number (in your case 13, in my case 2). This is a bad hash, meaning many things will sum to the same number. However, in this portion of the code:
if (patternHash == textHash) {
for (j = 0; j < patternLen; j++) {
if (text[i + j] != pattern[j])
break;
}
if (j == patternLen)
cout << "Pattern is found at position: " << i + 1 << endl;
}
you explicitly check the match, letter by letter, if the hashes match. The worse your hash function is, the more often you will have false positives (which will mean a longer runtime for your function). There are more details, but I believe that directly answers your question. What might be interesting is to record false positives and see how the false positive rate increases as d and q decrease.
I'm trying to write a programm to find a maximum value in column in a initialized 5x5 matrix, and change it to -1. I found out the way to do it, but i want to find a better solution.
Input:
double array2d[5][5];
double *ptr;
ptr = array2d[0];
// initializing matrix
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 5; ++j) {
if (j % 2 != 0) {
array2d[i][j] = (i + 1) - 2.5;
} else {
array2d[i][j] = 2 * (i + 1) + 0.5;
}
}
}
This is my solution for the first column :
// Changing the matrix using pointer arithmetic
for (int i = 0; i < (sizeof(array2d) / sizeof(array2d[0][0])); ++i) {
if (i % 5 == 0) {
if (maxTemp <= *(ptr + i)) {
maxTemp = *(ptr + i);
}
}
}
for (int i = 0; i < (sizeof(array2d) / sizeof(array2d[0][0])); ++i) {
if (i % 5 == 0) {
if (*(ptr + i) == maxTemp) {
*(ptr + i) = -1;
}
}
}
I can repeat this code 5 times, and get the result, but i want a better solution. THX.
Below is the complete program that uses pointer arithmetic. This program replaces all the maximum values in each column of the 2D array -1 as you desire.
#include <iostream>
int main()
{
double array2d[5][5];
double *ptr;
ptr = array2d[0];
// initializing matrix
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 5; ++j) {
if (j % 2 != 0) {
array2d[i][j] = (i + 1) - 2.5;
} else {
array2d[i][j] = 2 * (i + 1) + 0.5;
}
}
}
//these(from this point on) are the things that i have added.
//Everything above this comment is the same as your code.
double (*rowBegin)[5] = std::begin(array2d);
double (*rowEnd)[5] = std::end(array2d);
while(rowBegin != rowEnd)
{
double *colBegin = std::begin(rowBegin[0]);
double *colEnd = std::end(rowBegin[0]);
double lowestvalue = *colBegin;//for comparing elements
//double *pointerToMaxValue = colBegin;
while(colBegin!= colEnd)
{
if(*colBegin > lowestvalue)
{
lowestvalue = *colBegin;
//pointerToMaxValue = colBegin ;
}
colBegin = colBegin + 1;
}
double *newcolBegin = std::begin(rowBegin[0]);
double *newcolEnd = std::end(rowBegin[0]);
while(newcolBegin!=newcolEnd)
{
if(*newcolBegin == lowestvalue)
{
*newcolBegin = -1;
}
++newcolBegin;
}
++rowBegin;
}
return 0;
}
The program can be checked here.
You can add print out all the element of the array to check whether the above program replaced all the maximum value in each column with -1.
I have written it in java but I think u can understand. This one is for all 5 columns at the same time. You can try this:
int count = 0;
double max = 0;
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 5; ++j) {
if (j == 0) {
max = array2d[j][I];
count = 0;
}
if (array2d[j][i] > max) {
count = j;
}
}
array2d[count][i] = -1;
}
I have the following assignment:
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)
P A H N
A P L S I I G
Y I R
And then read line by line: "PAHNAPLSIIGYIR"
Write the code that will take a string and make this conversion given a number of rows:
string convert(string s, int numRows);
Example 1:
Input: s = "PAYPALISHIRING", numRows = 3
Output: "PAHNAPLSIIGYIR"
Example 2:
Input: s = "PAYPALISHIRING", numRows = 4
Output: "PINALSIGYAHRPI"
Explanation:
P I N
A L S I G
Y A H R
P I
The following is what I tried:
std::string convert(std::string s, int numRows) {
std::string answer = "";
std::vector<int> row1_indicies;
for (int i = 0; i < s.length(); i++)
{
if (numRows % 2 == 0)
{
row1_indicies.push_back(numRows*i+2*i);
}
else
{
row1_indicies.push_back(numRows*i+i);
}
if (row1_indicies[i] > s.length())
{
row1_indicies.pop_back();
break;
}
else if (row1_indicies[i] == s.length())
{
break;
}
}
for (int i = 0; i < numRows; i++)
{
for (int j = 0; j < row1_indicies.size(); j++)
{
if (i == 0)
{
answer += s[row1_indicies[j]];
}
else if (i == numRows-1)
{
answer += s[row1_indicies[j]+i];
}
else
{
if (j == 0)
{
answer += s[row1_indicies[j]+i];
}
else
{
answer += s[row1_indicies[j]-i];
answer += s[row1_indicies[j]+i];
}
}
}
}
return answer;
}
int main(){
std::string input = "PAYPALISHIRING";
int numRows = 4;
std::cout << "input = " << input << ", number of rows = " << numRows << std::endl;
std::string output = convert(input, numRows);
std::cout << output << " expected: PINALSIGYAHRPI" << std::endl << std::endl;
return 0;
}
My error occurs in the block:
else if (i == numRows-1)
{
answer += s[row1_indicies[j]+i];
}
When I debug I get "PINALSIGYAHR PI". It shows /000P is being returned when that index is accessed.
I added the following check to the block:
else if (i == numRows-1)
{
std::cout << std::endl << s.at(row1_indicies[j] + i) << std::endl;
answer += s[row1_indicies[j]+i];
}
Output looks like:
input = PAYPALISHIRING, number of rows = 4
P
I
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 15) >= this->size() (which is 14)
Any ideas?
The problem is there
else
{
answer += s[row1_indicies[j]-i];
answer += s[row1_indicies[j]+i];
}
You need this
else
{
answer += s[row1_indicies[j]-i];
if(row1_indicies[j]+i < s.length()){
answer += s[row1_indicies[j]+i];
}
}
Also add an else if and add an AND.
The for should look like this
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < row1_indicies.size(); j++) {
if (i == 0) {
answer += s[row1_indicies[j]];
}
else if (i == numRows-1 && row1_indicies[j]+i < s.length()) {
answer += s[row1_indicies[j]+i];
}
else if (i == numRows-1 && row1_indicies[j]+i > s.length()) {
return answer;
}
else {
if (j == 0) {
answer += s[row1_indicies[j]+i];
}
else {
answer += s[row1_indicies[j]-i];
if(row1_indicies[j]+i < s.length()) {
answer += s[row1_indicies[j]+i];
}
}
}
}
}
I know it doesn't answer your question, but why not something like this:
std::string convert(std::string s, int numRows)
{
std::vector <string> rows;
for(int i=0; i<numRows; i++)
{
rows.push_back(""); //every row is empty at the beginning
}
int repeatEvery = numRows + (numRows - 2); //numRows-2 says how many elements are on the diagonally (without the end and the beginning of the vertical columns)
int addRepeatValue = 0;
for(int i=0; i<s.length(); i++)
{
//going down the column
rows[i % repeatEvery] += s[i];
//upper right
if(i>= numRows-1 + addRepeatValue) // (numRows-1) + k*repeatEvery
{
for(int j=(numRows-1 + addRepeatValue-1)%(numRows-1); j>0; j--)
{
i++;
if(i == s.length()) break; //if it is already end of data then don't finish
rows[j] += s[i];
}
addRepeatValue += repeatEvery;
}
if(i == s.length()) break; //if it is already end of data then don't finish
}
string result="";
for(int i=0; i<rows.size(); i++) result += rows[i];
return result;
}
Well, if you try it on paper, you can easily figure out how to compute indices.
If numRows is 1, returns the string as it.
For top and bottom row, index increase by 2 * (numRows - 1).
For any row, the initial index is the index of the row.
For any row in between, increment alternate between:
2 * (numRows - index - 1)
2 * numRows.
Thus an algorithm like this will works:
std::string convert(std::string s, int numRows)
{
if (numRows <= 1) { return s; } // Required to avoid an infinite loop below
int offsetTotal = (numRows - 1) * 2;
int len = s.length();
std::string result;
for (int row = 0; row < numRows; ++row)
{
int index = row;
int offset = 2 * row;
while (index < len)
{
result += s[index];
if (offset != offsetTotal)
{
offset = offsetTotal - offset;
}
index += offset;
}
}
return result;
}
And if you want multiline output, an algorithm similar to this would do:
std::string convert(std::string s, int numRows)
{
if (numRows <= 1) { return s; }
int bloc_size = (numRows - 1) * 2;
int len = s.length();
int bloc_count = (len + bloc_size - 1) / bloc_size;
int width = bloc_count * (numRows - 1) + 1;
int size = width * numRows;
std::vector<char> data(size, ' ');
for (int i = width - 1; i < size; i += width) { data[i] = '\n'; }
std::vector<int> indexes;
bool down = true;
int index = 0;
int row = 0;
for (auto ch : s)
{
indexes.push_back(index);
data[index] = ch;
if (++row == numRows)
{
down = !down;
row = 1;
}
index += down ? width : 1 - width;
}
return { data.begin(), data.end() };
}
#include <stdio.h>
#include <bitset>
using namespace std;
short smallprimes[549]; // about 1100 bytes
char in[19531]; // almost 20k
int isprime(int j) {
if (j < 3)
return j == 2;
for (int i = 0; i < 549; i++) {
int p = smallprimes[i];
if (p * p > j)
break;
if (!(j % p))
return 0;
}
return 1;
}
void init() {
bitset<4000> siv;
for (int i = 2; i < 64; i++)
if (!siv[i])
for (int j = i + i; j < 4000; j += i)
siv[j] = 1;
int k = 0;
for (int i = 3; i < 4000; i += 2)
if (!siv[i]) {
smallprimes[k++] = i;
}
for (int a0 = 0; a0 < 10000000; a0 += 512) {
in[a0 / 512] = !a0;
for (int j = a0 + 1; j < a0 + 512; j += 2)
in[a0 / 512] += isprime(j);
}
}
int whichprime(int k) {
if (k == 2)
return 1;
int a = k / 512;
int ans = 1 + !a;
for (int i = 0; i < a; i++)
ans += in[i];
for (int i = a * 512 + 1; i < k; i += 2)
ans += isprime(i);
return ans;
}
int main() {
int k;
init();
while (1 == scanf("%i", &k))
printf("%i\n", whichprime(k));
}
This is my code. It shows the index value of the prime number in an array.
I want small code which can get index value of prime numbers store in an array. Or I enter a prime number and then program calculates prime number at that particular index and shows its index position.
Input: 2
Output: 1 (index in an array)
It's quite complicated. Looking for an alternate solution.
Here's my less complicated (fewer magic numbers) generic C approach to this problem. Like the OP's original code, it produces bad results if passed non-primes to index:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
typedef unsigned long PRIME;
bool *primes;
size_t calloc_size = 3;
void sieve(PRIME end) {
if (end >= calloc_size) {
primes = realloc(primes, end + 1);
memset(primes + calloc_size, true, end - calloc_size + 1);
calloc_size = end + 1;
}
// This might be optimized to not resieve old territory ...
for (size_t i = 0; i <= end; i++) {
if (primes[i]) {
for (size_t j = i * 2; j <= end; j += i) {
primes[j] = false;
}
}
}
}
// whichprime() returns 1-based index of target prime in primes array.
// Current and future results are indeterminate if argument isn't prime.
size_t whichprime(PRIME prime) {
if (prime < calloc_size) {
for (size_t i = 0, idx = 0; i < calloc_size; i++) {
if (primes[i]) {
idx++;
if (i == prime) {
return idx; // Target prime already in primes array
}
}
}
assert(false); // should never be reached
}
sieve(prime);
return whichprime(prime); // recurse as we now know it's in primes
}
int main() {
PRIME k;
// This could be optimized to not store even numbers ..
primes = calloc(calloc_size, sizeof(bool));
primes[calloc_size - 1] = true;
while (1 == scanf("%lu", &k)) {
printf("%lu\n", whichprime(k));
}
free(primes);
return 0;
}
The boolean primes array is a sieve that gets extended as needed.
USAGE
> ./a.out
2999
430
859433
68301
13
6
7919
1000
>
I have to calculate the values of a hot plate and have it accurate only to the first decimal place. I am stumped on trying to figure out how to check all the array values if they changed. I found out that 724 runs made no change after that to the 4th decimal (how many were being printed).
Is there a way to compare doubles variables only up to the n-th decimal place?
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int ARRAY_SIZE = 20;
const int NEIGHBORS = 4;
void initialize(double hot_plate[][ARRAY_SIZE]);
bool writeFile(const double HOT_PLATE[][ARRAY_SIZE],
const string FILE_NAME);
double sum_cell(const double HOT_PLATE[][ARRAY_SIZE],
const int CELL_X, const int CELL_Y);
int main()
{
double hot_plate[ARRAY_SIZE][ARRAY_SIZE];
initialize(hot_plate);
string file_name = "hot_plate.csv";
//accuracy up to 4 decmials
int runs = 724;
while ( runs > 0)
{
for (int i = 0; i < ARRAY_SIZE; i++)
{
for (int j = 0; j < ARRAY_SIZE; j++)
{
if (i > 0 && i < ARRAY_SIZE - 1 && j > 0 && j < ARRAY_SIZE - 1)
{
hot_plate[i][j] = sum_cell(hot_plate, j, i);
}
}
}
runs--;
}
if (writeFile(hot_plate, file_name))
{
cout << "File wrote correctly\n";
}
else
{
cout << "The file did not write!\n";
}
//system("pause");
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////// Completed Code ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
double sum_cell(const double HOT_PLATE[][ARRAY_SIZE],
const int CELL_X, const int CELL_Y)
{
/* This code should never go out of bounds as it's in an if statement
if (i > 0 && i < ARRAY_SIZE - 1 && j > 0 && j < ARRAY_SIZE - 1)
*/
double cell_num = HOT_PLATE[CELL_X - 1][CELL_Y]; // Top
cell_num += HOT_PLATE[CELL_X][CELL_Y - 1]; // Left
cell_num += HOT_PLATE[CELL_X][CELL_Y + 1]; // Right
cell_num += HOT_PLATE[CELL_X + 1][CELL_Y]; // Bottom
cell_num /= NEIGHBORS;
return cell_num;
}
// setup the Array so all values are defined when starting
void initialize(double hot_plate[][ARRAY_SIZE])
{
for (int i = 0; i < ARRAY_SIZE; i++)
{
for (int j = 0; j < ARRAY_SIZE; j++)
{
if (i == 0 || i == ARRAY_SIZE - 1)
{
if (j == 0 || j == ARRAY_SIZE - 1)
{
hot_plate[i][j] = 0.0;
}
else
{
hot_plate[i][j] = 100.0;
}
}
else
{
hot_plate[i][j] = 0.0;
}
}
}
}
// Write the data to the CSV file
bool writeFile(const double HOT_PLATE[][ARRAY_SIZE],
const string FILE_NAME)
{
// open the file
ofstream fout(FILE_NAME);
if (fout.fail())
return false;
for (int i = 0; i < ARRAY_SIZE; i++)
{
for (int j = 0; j < ARRAY_SIZE; j++)
{
fout << HOT_PLATE[i][j];
if ( j < ARRAY_SIZE - 1)
{
fout << ", ";
}
else if (i != ARRAY_SIZE - 1)
{
fout << endl;
}
}
}
// close the input stream from the file.
fout.close();
return true;
}
Is there a way to compare doubles variables only up to the n-th decimal place?
Yes there is, check whether the absolute value of the difference between them is less than 10^-n.
Check comparing floating point numbers and this post on deniweb.
With this function
double getUpToDecPlace (double value, int decPlace)
{
int dec = 1;
for (int i = 0; i < decPlace; i++)
{
dec *= 10;
}
return floor(value*dec + 0.5)/dec;
}
which would return 12.35 for getUpToDecPlace(12.345678, 2), you can compare doubles up to an arbitrary decimal place:
double var1 = 12.345678;
double var2 = 12.351234;
bool comp1 = (getUpToDecPlace(var1, 2) == getUpToDecPlace(var2, 2)); // true
bool comp2 = (getUpToDecPlace(var1, 3) == getUpToDecPlace(var2, 3)); // false
There are so many problems here.
You are updating the hot_plate array in-place. So some of the values you use from the 'previous generation' have already been updated in the current generation! You have to compute each generation in a separate array, and then copy it back to the 'master' hot_plate array.
If you want the final result accurate in the first decimal place, it's not enough to continue until the values don't change by more than 0.1. For instance, some values might change by more than 0.05 for ten more generations, which would amount to a change of more than 0.5. In fact, this is a very tricky issue: it requires a global analysis of how the initial conditions evolve over time.
Are you sure you have sum_cell right? The temperature of hot_plate[i][j] at the next generation should surely depend on the current value of hot_plate[i][j], and not just on its neighbours?
Also, this looks a bit silly:
for (int i = 0; i < ARRAY_SIZE; i++)
{
for (int j = 0; j < ARRAY_SIZE; j++)
{
if (i > 0 && i < ARRAY_SIZE - 1 && j > 0 && j < ARRAY_SIZE - 1)
I suggest the equivalent formulation:
for (int i = 1; i < ARRAY_SIZE - 1; i++)
{
for (int j = 1; j < ARRAY_SIZE - 1; j++)
As for testing equality to the nth decimal place, other posters have covered that.
Store the measured FP value as a scaled integer:
ix = int(fp * 10000)
You can then do direct comparisons with the required precision.