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

AA折れ線グラフ

入力は'R','F','C'の3種類の文字からなる長さ1以上の文字列 'R'は上昇を表し,折れ線グラフの要素としては '/' (スラッシュ)1文字に対応 'F'は下降を表し,折れ線グラフの要素としては '\' (バックスラッシュ)1文字に対応 'C'は変化なしを表し,折れ線グラフ…

差し金

差し金の形に 'a' を出力するプログラムです。 using System; using System.Collections.Generic; using System.Linq; class Program { static void Square(int n) { // 左下を (0, 0) とする for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { …

Enumerable.GroupBy メソッドで偶数と奇数に分ける

Enumerable.GroupBy メソッドで、数列を偶数と奇数に分けます。 クエリ式と、メソッド呼び出し構文の 2 通りの方法でプログラムを書いてみました。クエリ式いいですね。 using System; using System.Collections.Generic; using System.Linq; class Program …

Project Euler 56

PE

Problem 56 using System; using System.Collections.Generic; using System.Numerics; using System.Linq; class PE056 { static void Main() { var seq = from a in Enumerable.Range(1, 99) from b in Enumerable.Range(1, 99) let sum = BigInteger.Pow(…

Project Euler 55

PE

Problem 55 using System; using System.Collections.Generic; using System.Numerics; using System.Linq; // コンパイル方法: // $ mcs 055.cs -r:System.Numerics -out:a.exe class PE055 { static bool IsPalindrome(BigInteger n) { var a = n.ToString…

Project Euler 52

PE

Problem 52 6 倍しても桁が変わらないので、最上位の桁は 1 のはず。 using System; using System.Collections.Generic; using System.Linq; class PE052 { static void Main() { for (int i = 1; /* */; i++) { string s = "1" + i; // 6 倍しても桁数が同…

Project Euler 50

PE

Problem 50 using System; using System.Collections.Generic; using System.Linq; class Prime { public static List<int> Sieve(int n) { // n 以下の全ての素数を求める bool[] tab = new bool[n+1]; for (int i = 0; i < tab.Length; i++) tab[i] = true; int</int>…

Project Euler 49

PE

Problem 49 using System; using System.Collections.Generic; using System.Linq; class Prime { public static List<int> Sieve(int n) { // n 以下の全ての素数を求める bool[] tab = new bool[n+1]; for (int i = 0; i < tab.Length; i++) tab[i] = true; int</int>…

同じ数字のみからなる文字列かどうか(正規表現)

文字列が "111" や "888888" のように全て同じ数字であるかを調べるプログラムです。 正規表現を使っています。 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; class Program { static void M…