here is my code. pl tell me where its going wrong. tried all test cases I could think of.
[1]
[1]: http://www.codechef.com/viewsolution/4170389
here is my code. pl tell me where its going wrong. tried all test cases I could think of.
[1]
[1]: http://www.codechef.com/viewsolution/4170389
Here is the modified version of your code, just changed one line and it worked. Select it as the answer of your question if it helped ![]()
just change this
for(z=0;z<n;z++) //here i just changed this line for(z=0; finalstatus[z]!=‘\0’, z++)
{
if(finalstatus[z]==‘1’)
{
…
Complete modified code here
great,that worked. but i didn’t understand why the earlier “for(;finalstatus[z]!=’\0’;)” was wrong…??
in c++ ‘\0’ doesn’t have any special meaning. So when you are using it in for loop, your console just ignores it and loop continues.
Whereas, in c ‘\0’ it represents a null character.
#include
using namespace std;
int main()
{
char a[8];
int k=0;
for(int i=0;i<8;i++)
a[i]=‘z’;
a[3]='\0';
cout<<a<<"\n\n";
for(k=0;a[k]!='\0';k++);
cout<<k;
return 0;
}
when u run this code,ull get output showing k has gone from 0 to 3(and not 7 or anything else). i ran this in codeblocks with gcc…so the ‘\0’ terminating condition has always been working on my pc…