1 / 5
Mar 2020

#include
#include
using namespace std;
int main()
{
int i,j,k,temp;
string str;
long long int arr[5001];
arr[0]=1;
arr[1]=1;
cin>>str;
while(str[0]!=‘0’){
arr[0]=1;
arr[1]=1;
for(i=2;i<=str.length();i++){
if(str[i-1]!=‘0’)
arr[i]=arr[i-1];
temp=(str[i-2]-‘0’)*10+(str[i-1]-‘0’);
if(temp>=10 && temp<=26)
arr[i]+=arr[i-2];
arr[i-2]=0;
}
cout<<arr[i-1]<<endl;
arr[i-2]=0;
arr[i-1]=0;
cin>>str;
}
return 0;
}

What’s wrong in my code?

  • created

    Mar '20
  • last reply

    Mar '20
  • 4

    replies

  • 629

    views

  • 2

    users

  • 1

    like

  • 2

    links

But still i have one more doubt that is-
As per my knowledge there is no default value given to an array in c++,garbage value is present.
Also i haven’t initialized my whole array by zero, still it is working and giving correct answer.
Also i checked the values of my array after initializing it.They were zero.
What’s the matter here?

Can anyone explain this concept to me .
I shall be very thankful to him.

Suggested Topics

Want to read more? Browse other topics in Online Judge System or view latest topics.