Determine the word/words with the greatest consonant to vowel ratio.
Notes:
→ No proper nouns, abbreviations/acronyms, slangs, esoteric/archaic words. Also, hyphenated words like A-bomb are NOT permissible.
→ Consider Y as a vowel.
→ The word must have at least one vowel.
clearvars,clc
maxratio=0;
fid=fopen("c:\words\words.txt","r");
while ~feof(fid)
w=fgetl(fid);
if ~isequal(w,lower(w))
continue
end
l=length(w);
vowels=0;
for i=1:l
if contains("aeiouy",w(i))
vowels=vowels+1;
end
end
if vowels==0
continue
end
ratio=(l-vowels)/vowels;
if ratio>=maxratio
disp([w ' ' char(string(ratio))])
maxratio=ratio;
end
end
fclose(fid);
finds at the end
strengths 8
tsktsking 8
|
Posted by Charlie
on 2022-04-03 10:20:47 |