C♯の勉強

C♯4.0 で TopCoder の過去問を解きます。

TopCoder SRM598: FoxAndFencing

public class FoxAndFencing {
    const string Ciel = "Ciel";
    const string Liss = "Liss";
    const string Draw = "Draw";
    public string WhoCanWin(int mov1, int mov2, int rng1, int rng2, int d) {
        if (mov1 + rng1 >= d)
            return Ciel;
        if (mov1 + d <= mov2 + rng2)
            return Liss;
        if (mov1 == mov2)
            return Draw;
        if (mov1 < mov2) {
            if (mov1 + rng1 + 1 + mov1 <= mov2 + rng2)
                return Liss;
        }
        if (mov1 > mov2) {
            if (mov2 + rng2 + 1 + mov2 <= mov1 + rng1)
                return Ciel;
        }
        return Draw;
    }
}