Hi everyone,
I just finished the problem after some debugging. The only thing I changed was how I declared varibles in my boolean function.
Before I declared them with this (setting to zero?):
int A, C, G, T;
After realizing it was the problem, I changed the declaration to this:
int A = 0; C=0, G=0, T=0;
Then the code worked. What is the difference between the two? Here is my full code:
#include<iostream>
#include<fstream>
using namespace std;
int N, M;
char spot[100][100];
char plain[100][100];
//bool function for checking a collumn of genomes
bool checkline(int collumn){
int A = 0,C = 0,G = 0,T = 0; //variable declarations
int A2 = -1, C2 = -1, G2 = -1, T2 = -1;
for(int n=0; n < N; n++) { //Using ints to note whether two Genomes were used in both
//If statements checking to see if a genome was in the seletced spot
if(A==0 && spot[n][collumn] == 'A') {
A = 1;
}else if (C==0 && spot[n][collumn] == 'C') {
C = 1;
}else if (G==0 && spot[n][collumn] == 'G') {
G = 1;
}else if (T==0 && spot[n][collumn] == 'T') {
T = 1;
}
if(A2==-1 && plain[n][collumn] == 'A') {
A2 = 1;
}else if (C2==-1 && plain[n][collumn] == 'C') {
C2 = 1;
}else if (G2==-1 && plain[n][collumn] == 'G') {
G2 = 1;
}else if (T2==-1 && plain[n][collumn] == 'T') {
T2 = 1;
}
}
//return true or false after int setting is done
if(A == A2 || C == C2|| G == G2||T == T2){
return false;
} else {
return true;
}
}
int main() {
ifstream fin("cownomics.in");
ofstream fout("cownomics.out");
fin >> N >> M;
for(int n = 0; n < N; n++){
for(int m = 0; m < M; m++){
fin >> spot[n][m];
}
}
for(int n = 0; n < N; n++){
for(int m = 0; m < M; m++){
fin >> plain[n][m];
}
}
int ans=0;
for(int collumn = 0; collumn < M; collumn++){
if(checkline(collumn)){
ans++;
}
}
fout << ans << "\n";
}