Old Magic!

You: Guess an integer number, but don’t tell me. Your friend: Okay! You: Now multiply it by 3. Your …

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

Please read the problem statement carefully.

You can safely assume that after any operation, the number your friend got will be an integer and will not exceed 64-bit signed integer.

what is the problem with this code??

#include<stdio.h>
int main()
{
int n;
scanf(“%d”,&n);
int a[n],i;
long long int m;
char p[n];
for(i=0;i<n;i++){
scanf(“%s%d”,&p[i],&a[i]);
}
scanf(“%lld”,&m);
for(i=n;i>=0;i–){
if(p[i]==‘a’)m-=a[i];
else if(p[i]==‘s’)m+=a[i];
else if(p[i]==‘m’)m/=a[i];
else if(p[i]==‘d’)m*=a[i];
}
printf(“%lld”,m);
return 0;
}

ain’t you mistaking characters with strings?

char p[n]; // p is declared as a string here.

for (i = 0; i < n; i++){
    scanf("%s%d",&p[i],&a[i]);
                  ^^^ but why are you taking inputs as characters here?
}

It said WA not complication error.
What should i do?

It is not a Compilation error but an error in your codes logic. Though I have already pointed out the error already, try to find out what is wrong yourself.