blob: af05e1ba16cc0f56643d5342314d0f0b1647a68c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
import std.stdio:writeln,write;
import std.uni:toLower;
import std.algorithm:map,all,canFind;
import std.array:array;
bool all_match(ref string s1, ref string s2)
{
foreach(ref c;s1) if(!canFind(s2,c)) return false;
return true;
}
void keyboard_word(ref string[] words)
{
string[] qwerty = ["qwertyuiop","asdfghjkl","zxcvbnm"];
words = words.map!(toLower).array;
foreach(ref q;qwerty)
foreach(ref w;words) if(all_match(w,q)) write(w,' ');
writeln;
}
void main()
{
string[] words1 = ["Hello","Alaska","Dad","Peace"];
string[] words2 = ["OMG","Bye"];
keyboard_word(words1);
keyboard_word(words2);
}
|