0

int count[N][N] = {0}; where N is a value received at runtime. I am unable to figure out why this one element is initializing to this value. Below I have added the code it is included in just in case if it is being affected by anything else. Thank you already.enter image description here

string s;
cin>>s;

set<char> setStr;
string unique;
vector<int> numStr;

for(auto c: s) setStr.insert(c);

for(auto x: setStr) unique.push_back(x);

for(auto c: s) numStr.push_back(unique.find(c));

int N = (int) unique.size();


int pair[N][N] = {-1};
int count[N][N] = {0};



cout<<endl;
for(auto n: numStr)
{
    for(int col=0;col<N;++col)
    {
        if(pair[n][col]==n) count[n][col]=-1;
        if(count[n][col]!=-1)
        {
            pair[n][col]=n;
            ++count[n][col];
        }
    }
    
    for(int row=0;row<N;++row)
    {
        if(pair[row][n]==n) count[row][n]=-1;
        if(count[row][n]!=-1)
        {
            pair[row][n]=n;
            ++count[row][n];
        }
    }

}
  • 3
    [Why aren't variable-length arrays part of the C++ standard?](https://stackoverflow.com/questions/1887097/why-arent-variable-length-arrays-part-of-the-c-standard) – 273K May 23 '21 at 06:11
  • 2D arrays do not support initialization in the way you've mentioned. That only works for 1D arrays – diviquery May 23 '21 at 19:03

0 Answers0