GUI编程的任务暂时告一段落,现在又要开始每天刷一道题目的日子了。
(1)Problem 13. Remove all the consonants
Remove all the consonants in the given phrase.
Example:
Input s1 = 'Jack and Jill went up the hill';
Output s2 is 'a a i e u e i';
要想去掉所有的辅音,就要构建一个包含所有辅音的数组,然后逐一进行判断。
答:
function s2 = refcn(s1)
s2='';
k=1;
flag=0;
L=strlength(s1);
s3='BbCcDdFfGgHhJjKkLlMmNnPpQqRrSsTtVvWwXxYyZz';
L1=strlength(s3);
for i=1:L
for j=1:L1
if s1(i)==s3(j)
flag=1;
continue;
end
end
if flag==0
s2(k)=s1(i);
k=k+1;
end
flag=0;
end
end