Hmm i am using a ruby code for this…not sure why its breaking through
#!/usr/bin/env ruby
get_string=gets
array_comp = ""
chef_count = 0
get_string.split('').each do |character|
if character == "C" && array_comp == ""
array_comp.concat("C")
end
if character == "H" && array_comp.length == 1
array_comp.concat("H")
end
if character == "E" && array_comp.length == 2
array_comp.concat("E")
end
if character == "F" && array_comp.length == 3
array_comp.concat("F")
chef_count += 1
array_comp = ""
end
end
puts chef_count.to_i
#include
#include<string.h>
using namespace std;
int main()
{
long int counte,counth,countc,countf,ans;
char ch[100001];
cin>>ch;
long int n=strlen(ch);
countc=counth=counte=countf=ans=0;
for(int i=0;i<n;i++)
{
if(ch[i]==‘C’)
{
//cout<<“STARTED FOUNDING CHEF . C LETTER FOUNDED\n”;
countc++;
}
else
if(ch[i]==‘H’&&countc>0)
{
//cout<<“H LETTER FOUND.\n”;
counth++;
}
else
if(ch[i]==‘E’&&counth>0&&countc>0)
{
//cout<<“E LETTER FOUND.\n”;
counte++;
}
else
if(ch[i]==‘F’&&counte>0&&counth>0&&countc>0)
{
//cout<<“F LAST LETTER FOUND.RESETTING ALL.\n”;
counte=counth=countc=0;
//cout<<“ANSWER NOW INCREMENTED.\n”;
ans++;
//cout<<“ANSWER NOW “<<ans<<” \n”;
}
}
cout<<ans<<"\n";
}
Please tell whats wrong in my code??
I don’t know whats wrong in my below code. Kindly help me to find out the error in that.
def string_manipulation(ipstring):
cond = ‘CHEF’
result = 0
alist = list(map(lambda x: x,ipstring))
if (len(ipstring) >= 1 and len(ipstring) <= 100000) and ipstring.isupper() == True:
ipstring_indexes = [x for x in range(len(alist)) if alist[x]==list(map(lambda x: x,cond))[0]]
for loop in range(0,len(ipstring_indexes)):
if len(ipstring_indexes)-1 != loop:
num = alist[ipstring_indexes[loop]:ipstring_indexes[loop+1]]
else:
num = alist[ipstring_indexes[loop]:len(alist)-1]
if “”.join([n for i, n in enumerate(num) if i==0 or n != num[i-1]]) == cond:
result = result+1
else:
result = 0
return result
print string_manipulation(raw_input(‘Enter String’))
s=input()
d={}
for i in s:
if i==“C”:
if d.get(i)==None:
d[i]=1
else:
d[i]+=1
if d.get(“C”)!=None:
if d.get(i)==None:
d[i]=1
else:
if d[i]<d[“C”]:
d[i]+=1
print(min(d.values()))
i dont know where my code is failing.`s=input()
d={}
for i in s:
if i==“C”:
if d.get(i)==None:
d[i]=1
else:
d[i]+=1
if d.get(“C”)!=None:
if d.get(i)==None:
d[i]=1
else:
if d[i]<d[“C”]:
d[i]+=1
print(d)
print(min(d.values()))
the route in chef is C > H > E > F
you are always chking possibility of route directly from
C to E in 1st else if block | correct
C to H in 2nd else if block | incorrect , change it
C to F in 3nd else if block | incorrect , change it
ONLY THESE MINUTE CHANGES AND YOUR CODE WILL BE PERFECT FOR ALL TEST DATA
My code is pretty much equivalent to yours, and I get a WA (Wrong Answer) when I submit it. I can’t figure out which string would give me a wrong answer. Did you ever figure out what is wrong with yours?