Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
45
Task/ABC-Problem/Apex/abc-problem.apex
Normal file
45
Task/ABC-Problem/Apex/abc-problem.apex
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
static Boolean canMakeWord(List<String> src_blocks, String word) {
|
||||
if (String.isEmpty(word)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<String> blocks = new List<String>();
|
||||
for (String block : src_blocks) {
|
||||
blocks.add(block.toUpperCase());
|
||||
}
|
||||
|
||||
for (Integer i = 0; i < word.length(); i++) {
|
||||
Integer blockIndex = -1;
|
||||
String c = word.mid(i, 1).toUpperCase();
|
||||
|
||||
for (Integer j = 0; j < blocks.size(); j++) {
|
||||
if (blocks.get(j).contains(c)) {
|
||||
blockIndex = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (blockIndex == -1) {
|
||||
return false;
|
||||
} else {
|
||||
blocks.remove(blockIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
List<String> blocks = new List<String>{
|
||||
'BO', 'XK', 'DQ', 'CP', 'NA',
|
||||
'GT', 'RE', 'TG', 'QD', 'FS',
|
||||
'JW', 'HU', 'VI', 'AN', 'OB',
|
||||
'ER', 'FS', 'LY', 'PC', 'ZM'
|
||||
};
|
||||
System.debug('"": ' + canMakeWord(blocks, ''));
|
||||
System.debug('"A": ' + canMakeWord(blocks, 'A'));
|
||||
System.debug('"BARK": ' + canMakeWord(blocks, 'BARK'));
|
||||
System.debug('"book": ' + canMakeWord(blocks, 'book'));
|
||||
System.debug('"treat": ' + canMakeWord(blocks, 'treat'));
|
||||
System.debug('"COMMON": ' + canMakeWord(blocks, 'COMMON'));
|
||||
System.debug('"SQuAd": ' + canMakeWord(blocks, 'SQuAd'));
|
||||
System.debug('"CONFUSE": ' + canMakeWord(blocks, 'CONFUSE'));
|
||||
Loading…
Add table
Add a link
Reference in a new issue