Little elephant and strings
http://www.codechef.com/viewsolution/1052277
Why is this code getting RTE?
Any help will be appreciated
And, by the way, how can I change my country code?
The code encountered the Runtime error due to the function::
bool substring(string s1,string s2)
{
for(int i=0;i<s1.length()-s2.length()+1;i++)
{
if(s1.string::substr(i,s2.length())==s2)
return true;
}
return false;
}
See there is no-where written in the problem statement that (favorite_lucky_strings).length <= pillow_string.length();
After looking at your code I can easily say that you assumed favorite_lucky_strings).length() <= pillow_string.length(); while writing the code and YES this cause the RTE.
Consider the Testcase::
1 1
74747474
47
good[0]=โ74747474โ;
pill=โ47โ;
call substring(pill,good[0]);
In Substring Function::
S1= 47
S2=74747474
s1 Length=2
s2 Length=8
s1.length()-s2.length()+1 = -5
So the for loop will run for i=0,1,2,3,โฆ as
I val is: 0 .The Substring is 47
I val is: 1 .The Substring is 7
I val is: 2 .The Substring is
I val is: 3. out_of_range ie,RUNTIME ERROR.
I am pasting the result/output generated by my compiler for the above testcase
input:
1 1
74747474
47
output:
S1:: 47
S2:: 74747474
s1 Length:2
s2 Length:8
s1.length()-s2.length()+1 -5
I val is: 0 .The Substring is 47
I val is: 1 .The Substring is 7
I val is: 2 .The Substring is
I val is: 3
stderr:
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr**95
Check your code run at IDEONE.com for the above test case
YOUR SECOND QUESTION
how can I change my country code?
Step 1:Log in to your Codechef Account.
Step 2:Edit profile.
Step 3: Select the desired country from "What country do you currently live in?: " select Menu.
Thank you, but (if Iโm not wrong) if |s1|-|s2|+1<0 it wonโt enter for loop, am I right? Again, thanks
For second question, Iโve already done that, and it changed the country on my account(not on this profile, I ask for some other) and the country code didnโt changed.
I want to change country code cause of country rank.
@vladimirmsrb:: The same problem i encountered a few dayz back.
Your country code will get updated after the coming June Long Contest as the country code and Rankings get updated at the same time.So ,u have to wait till June 11.
OK, thanks