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

×

Please help me in TWSTR

I am trying to solve remember the recipe problem. https://www.codechef.com/problems/TWSTR

although i have written my codes and tested it on PC ,here it is giving WA.I have checked that whether my data types are correct or not.As per me they are correct.I think my solution is doing way more computation than required(this is my guess) .Plz check my code and help me so i could submit it correctly.This is my solution. https://www.codechef.com/viewsolution/17563758

asked 28 Feb '18, 12:26

jshobhit's gravatar image

0★jshobhit
1
accept rate: 0%

converted to question 28 Feb '18, 15:49

vijju123's gravatar image

5★vijju123 ♦♦
15.4k12066


Your is_Word() function is wrong. It is returning true even for strings which are not. Try running your code in Codechef IDE, its printing fish with pepper for all queries in sample input.

Basically the problem is here-

if(input[i] == word[i]) {
            if(i==input.length()-1) {
                return true;
            }
        }
        else{
            break;//Causes it to break out of loop skipping the return statement.
            return false;
        }
link

answered 28 Feb '18, 16:00

vijju123's gravatar image

5★vijju123 ♦♦
15.4k12066
accept rate: 18%

link

answered 28 Feb '18, 19:39

jshobhit's gravatar image

0★jshobhit
1
accept rate: 0%

hey. as you said i tried running my codes on codechef ide. And yes it is giving wrong answer,i don't know why , while running on my pc it is giving correct answer.What could be the reason,i mean how one code which running fine in my pc is giving wrong answer here.

link

answered 28 Feb '18, 19:45

jshobhit's gravatar image

0★jshobhit
1
accept rate: 0%

That means your code runs on undefined behaviour for some inputs. Happens due to array-out-of-bounds exception etc. Eg, in your isWord function,

for(int i=0;i<input.length();i++) { if(input[i] == word[i]) {

What if length of word is less than length of input? :)

(28 Feb '18, 19:51) vijju123 ♦♦5★

NEED HELP GUYS sorry i m posting it here but i don't have that much point to post a question


a recent ICL2018 a queston called MATRIX GAME was there can anyone help me with that i can't find what i did wrong in my code. Please guyss Please....

Here's my code link : https://www.codechef.com/viewsolution/17567231

it's giving me wrong answer... ............

link

answered 28 Feb '18, 21:19

keshav_'s gravatar image

4★keshav_
11
accept rate: 0%

edited 28 Feb '18, 21:24

Very silly error.

Input 1 1 1 0 Your Output Cyborg Expected Output Draw

Similar if matrix is all 0s.

(28 Feb '18, 21:30) vijju123 ♦♦5★

Thank you!! I haven't considered the case that it can be '0'. Thanks, @vijju123

(01 Mar '18, 09:03) keshav_4★
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:

×3,764
×2,718
×1,070
×643
×123

question asked: 28 Feb '18, 12:26

question was seen: 225 times

last updated: 01 Mar '18, 09:03