I want to say that most of the Code is well and functioning, BUT when there are bigger data, it just malfunctions. I got 30 point out of 100 for it so far.
The row's first numbers are the rows of after the first line, and the second one is the number of datas that are in those rows. After that those are the datas that I need to work with. I store them in bemenet 2 dimensional array.
My exercise was to find out which rows had at least 2 non 0 numbers in it. And then report it in a Matrix which size is: the second number from the first row^2.
So because of this I searched which rows have at least 2 non 0 numbers in them, then I put them in a Vector, and what I tried to do was to have like a relation thing, when like for example 1,2, and 4 are selected, the output will be all 0s except the 1st row 2nd 1st row 4th, 2nd row 1st, 2nd row 4th, and 4th row 1st and 2nd. In the in1.txt it works just like this, and is perfect, however, for the in2. Every value except for the main diagonal will be 1. I don't know what I did wrong, and I've been trying for the last 2 hours to solve this.
Can someone try to help, or explain me what my error is? Any help would be appreciated! Here's my source code so far:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct adatok{
int szam = 0;
bool alkalmi = false;
};
bool IsZero(int a){
if(a == 0) return true;
else return false;
}
int indexOf(vector<auto> v, auto item){
for(int i=0; i <v.size();++i)
if(item == v[i]) return i;
return -1;
}
bool contains(vector<auto> v, auto item){
return indexOf(v,item) != -1;
}
int main()
{
int n = 0, m = 0;
cin >> n >> m;vector<int> vektor;
adatok bemenet[n][m];
for (int i = 0; i < n; i++){
int seged = 0;
for (int j = 0; j < m; j++){
cin >> bemenet[i][j].szam;
if (!IsZero(bemenet[i][j].szam)){
seged++;
}
}
if (seged >= 2){
for(int j = 0; j < m; j++){
if(!IsZero(bemenet[i][j].szam)){
vektor.push_back(j);
}
}
}
}
sort( vektor.begin(), vektor.end() );
vektor.erase( unique( vektor.begin(), vektor.end() ), vektor.end() );
for (int i = 0; i < m; i++){
for (int j = 0; j < m; j++){
if (i == j) cout << "0";
else if(contains(vektor, i) && contains(vektor, j)){
cout << "1";
}
else cout << "0";
}
cout << "\n";
}
return 0;
}