You are not logged in. Please login at www.codechef.com to post your questions!

×

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);
    }

asked 22 Sep '13, 13:27

rtandon90210's gravatar image

0★rtandon90210
125
accept rate: 0%

edited 22 Sep '13, 16:41

tijoforyou's gravatar image

2★tijoforyou
4.2k52364

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

(22 Sep '13, 13:38) gautam943★

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.
link

answered 22 Sep '13, 16:46

tijoforyou's gravatar image

2★tijoforyou
4.2k52364
accept rate: 15%

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);
    }
link

answered 22 Sep '13, 16:58

abhishek0994's gravatar image

0★abhishek0994
1
accept rate: 0%

edited 22 Sep '13, 17:01

tijoforyou's gravatar image

2★tijoforyou
4.2k52364

1

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.

(22 Sep '13, 17:03) tijoforyou2★

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

link

answered 22 Sep '13, 18:28

rtandon90210's gravatar image

0★rtandon90210
125
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×242
×1
×1

question asked: 22 Sep '13, 13:27

question was seen: 552 times

last updated: 22 Sep '13, 18:28