'I can't figure out why hash[0] is being assigned the value 1 in the output . Any help would be appreciated
This is my code:-
#include<iostream>
#include<string>
using namespace std;
int main()
{
string magazine="aab";
string ransomNote="aa";
int hash[123]={};
int i;
for(i=0;i<=magazine.length();i++)
{
hash[magazine[i]]++;
}
for(i=0;i<123;i++)
{
cout<<hash[i]<<" ";
}
cout<<endl;
}
The output is:-
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
