Created
November 10, 2013 14:50
-
-
Save tekkoc/7399120 to your computer and use it in GitHub Desktop.
最強最速アルゴリズマー養成講座P63より
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
import std.algorithm; | |
import std.range; | |
void main() | |
{ | |
auto first = ["fishing", "gardening", "swimming", "fishing"]; | |
auto second = ["hunting", "fishing", "fishing", "biting"]; | |
writeln((new InterestingParty()).bestInvitation(first, second)); | |
} | |
class InterestingParty | |
{ | |
int bestInvitation(string[] first, string[] second) | |
{ | |
int[string] counting; | |
foreach (interesting; zip(first, second)) { | |
counting[interesting[0]]++; | |
counting[interesting[1]]++; | |
} | |
return counting.values.sort.reverse[0]; | |
} | |
unittest | |
{ | |
auto first = ["fishing", "gardening", "swimming", "fishing"]; | |
auto second = ["hunting", "fishing", "fishing", "biting"]; | |
auto result = 4; | |
assert(result == (new InterestingParty()).bestInvitation(first, second)); | |
} | |
unittest | |
{ | |
auto first = ["variety", "diversity", "loquacity", "courtesy"]; | |
auto second = ["talking", "speaking", "discussion", "meeting"]; | |
auto result = 1; | |
assert(result == (new InterestingParty()).bestInvitation(first, second)); | |
} | |
unittest | |
{ | |
auto first = ["snakes", "programming", "cobra", "monty"]; | |
auto second = ["python", "python", "anaconda", "python"]; | |
auto result = 3; | |
assert(result == (new InterestingParty()).bestInvitation(first, second)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment