Please help me in TWSTR

help
debug
easy
string
wa

#1

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


#2

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* == word*) {
			if(i==input.length()-1) {
				return true;
			}
		}
		else{
			break;//Causes it to break out of loop skipping the return statement.
			return false;
		}

#3

https://www.codechef.com/viewsolution/17566611 .But i am still getting error


#4

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.


#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…


#6

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* == word*) {

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


#7

Very silly error.

Input 1 1 1 0 Your Output Cyborg Expected Output Draw

Similar if matrix is all 0s.


#8

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