Problem with my code for flames game

This is my code in matlab for flames game but unable to get expected output.
Please check the code and help me to solve the problem
In this i am comparing two strings and replacing matching charaecters with '/' and also counting and at the end counting the number(n) of remaining charaecters other than '/' and incrementing pointer for flames string until n becomes zero for five times and replacing all such charecters in flames with '/'
p=input('Enter the first string:'); o=input('Enter the second string:'); c=size(p,2); d=size(o,2); for i=1:c for j=1:d if(p(i)==o(j)) p(i)='/'; o(j)='/'; else disp('Do_nothing'); end end end f=0; for i=1:c if(p(i)~='/') f=f+1; else disp('Do_nothing'); end end q=0; for j=1:d if(o(j)~='/') q=q+1; else disp('Do_Nothing'); end end handles.g=f+q; n=0; h='FLAMES'; for m=1:handles.g n=n+1; end v=n; i=1; for v=1:5 while(n) if(n>1) n=n-1; if(h(i)~='S') i=i+1; elseif(h(i)=='S') i=0; elseif(h(i)=='/') i=i+1; n=n+1; end end if(n==1) if(h(i)~='S') i=i+1; elseif(h(i)=='S') i=0; elseif(h(i)=='/') i=i+1; n=n+1; end end end W=regexprep(h,'h(i)','/'); end %disp('So the relationship between you has:'); %k;
Thanks in advance.

1 个评论

Try this
function Match=FLAMES(nm1,nm2)
letter2number = @(c)1+lower(c)-'a';
A=letter2number(nm1);
B=letter2number(nm2);
C=[];
for i=1:length(A)
z=find(A(i)==B);
if length(z)>0
B(z(1))=[];
C=[C i] ;
end
end
R=(length(A)-length(C))+length(B);
Match='FLAMES';
for i=1:5
s=mod(R,7-i);
if s==0
Match(end)=[];
else
Match(s)=[];
end
end
return
Example
Match=FLAMES('sivakumar','indhu')
Output
Match =
'A'

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Just for fun 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by