Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
26
Task/ABC-Problem/MATLAB/abc-problem.m
Normal file
26
Task/ABC-Problem/MATLAB/abc-problem.m
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
function testABC
|
||||
combos = ['BO' ; 'XK' ; 'DQ' ; 'CP' ; 'NA' ; 'GT' ; 'RE' ; 'TG' ; 'QD' ; ...
|
||||
'FS' ; 'JW' ; 'HU' ; 'VI' ; 'AN' ; 'OB' ; 'ER' ; 'FS' ; 'LY' ; ...
|
||||
'PC' ; 'ZM'];
|
||||
words = {'A' 'BARK' 'BOOK' 'TREAT' 'COMMON' 'SQUAD' 'CONFUSE'};
|
||||
for k = 1:length(words)
|
||||
possible = canMakeWord(words{k}, combos);
|
||||
fprintf('Can%s make word %s.\n', char(~possible.*'NOT'), words{k})
|
||||
end
|
||||
end
|
||||
|
||||
function isPossible = canMakeWord(word, combos)
|
||||
word = lower(word);
|
||||
combos = lower(combos);
|
||||
isPossible = true;
|
||||
k = 1;
|
||||
while isPossible && k <= length(word)
|
||||
[r, c] = find(combos == word(k), 1);
|
||||
if ~isempty(r)
|
||||
combos(r, :) = '';
|
||||
else
|
||||
isPossible = false;
|
||||
end
|
||||
k = k+1;
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue