Hatena::Groupfizzbuzz

mattnの日記

 | 

2010-03-24しーしゃーぷとか

C#

17:45

class FizzBuzz {
  private int n = 1;
  public static FizzBuzz operator ++(FizzBuzz f) { ++f.n; return f; }
  public static bool operator ==(FizzBuzz f, int n) { return f.n == n; }
  public static bool operator !=(FizzBuzz f, int n) { return !(f==n); }
  public override string ToString() {
    return n%15>0?n%3>0?n%5>0?n.ToString():"Buzz":"Fizz":"FizzBuzz";
  }
  static void Main() {
    for (FizzBuzz fb = new FizzBuzz(); fb != 101; fb++)
      System.Console.WriteLine(fb);
  }
}
// vim: set et:

ゲスト



トラックバック - http://fizzbuzz.g.hatena.ne.jp/mattn/20100324
 |