why isnt my code for Code Crazy Minions working...i cant find my fault with the logic applied by me>????

#include<stdio.h>
#include<string.h>
char word[1000];
int ins=0;
int val1,val2;
int main()
{
int ins=0,i,tc;
scanf("%d/n",&tc);
while(tc–)
{
enterword();
ins=countins();
display(ins);
}
return 0;
}
void enterword()
{
scanf("%s",&word);
}
int countins()
{
int i;
for(i=0;i<strlen(word);i++)
{
int val1,val2;
ins++; //load//
val1=word[i];
val2=word[i+1];
if(val2<val1)
{
ins=ins+val2+(122-val1)+1; printf("%d\n",ins);
}
else
{
ins=ins+(val2-val1)+1; //instructions are counted
}
}
return ins;
}
void display(int ins)
{
if(ins<(11*strlen(word)))
printf("%d yes",ins);
else

                 printf("%d no",ins);
    }

If you find it hard to format your code properly, then use ideone.com and post the link here.

I see at least these:

  1. It is \n, not /n.
  2. You don’t use an ampersand (&) when reading a string with scanf.
  3. I haven’t seen the question, but I guess you need to output a \n at the end, in the function display.
1 Like

there are some syntax errors in your code :
1)scanf("%d/n",&tc); … it should be scanf("%d",&tc);
2) enterword()and countins() must be prototyped before use i.e before main() …

i have corrected the m… now the code works fine … check it out and tell me …

#include<stdio.h>
#include<string.h>
#include<conio.h>
using namespace std;
char word[1000];
int ins=0;
int val1,val2;
void enterword();
int countins();
void display(int x);
int main()
{
int i,tc;
scanf("%d",&tc);
while(tc--)
    {
    enterword();
    ins=countins();
    display(ins);
    }
    getch();
return 0;
}
void enterword()
{
scanf("%s",word);
}
int countins()
{		
    int i;
for(i=0;i<strlen(word);i++)
    {
    int val1,val2;
    ins++;       //load//
    val1=word[i];
    val2=word[i+1];
    if(val2<val1)
        {
            ins=ins+val2+(122-val1)+1; printf("%d\n",ins);
        }
    else
        {
            ins=ins+(val2-val1)+1; //instructions are counted
        }
    }
   return ins;
   }
void display(int ins)
    {
                if(ins<(11*strlen(word)))
                printf("%d yes",ins);
              else
                 printf("%d no",ins);
    }

What is it with the “conio.h”

That is ANSI C. Here at codechef, we no longer use it. We use gcc to compile our code, so anything and everything that gcc rejects will not be accepted at codechef.

1 Like

still not getting through with the problem…kindly help me with the logic!!although from my side its correct1!!

//