2015-07-01から1ヶ月間の記事一覧

Mono: checked キーワードを使わずに、オーバーフローチェックを有効にする

以下の記事で、Visual Studio では checked キーワードを使わなくても、ビルド設定でオーバーフローチェックができるとありました。 競技プログラミングのための C# (4.0 以降) の Tips 詰め合わせ - C♯の勉強 Mono でも checked キーワードを使わずにオー…

0..6 の範囲でぐるぐる回る

mod

0..6 の範囲でぐるぐる回るサンプルです。 以下の、上の段の数値を下の段の数値に変換するサンプルです。 -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ↓に変換する 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, …

Codeforces 1B - Spreadsheets

Problem - 1B - Codeforces using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; class Program { // A, B, C, ..., Y, Z, AA, AB, AC, ... を返す static IEnumerable<string> Seq() { // A = 1, B = 2, Y </string>…

Convert クラスで基数変換

Convert クラスを使用して基数変換を行うサンプルです。 using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { for (int i = 0; i < 256; i++) { var bin = Convert.ToString(i, 2); var oct = Conver…

Python の itertools.repeat を C# で作る。その 2

Python の itertools.repeat を C# で作る の、その 2 です。 using System; using System.Collections.Generic; using System.Linq; class Iter { public static IEnumerable<T> Repeat<T>(T obj) { for (;;) { yield return obj; } } public static IEnumerable<T> </t></t></t>…

Python の itertools.count を C# で作る

Python の itertools.count を C# で作ってみます。 using System; using System.Collections.Generic; using System.Linq; class Iter { public static IEnumerable<int> Count(int start, int step=1) { int x = start; while (true) { yield return x; x += st</int>…

Python の itertools.cycle を C# で作る

Python の itertools.cycle を C# で作ってみます。 using System; using System.Collections.Generic; using System.Linq; class Iter { public static IEnumerable<T> Cycle<T>(IEnumerable<T> seq) { for (;;) { bool empty = true; foreach (var elt in seq) { yi</t></t></t>…