Skip to content

Instantly share code, notes, and snippets.

@yjiro0403
Last active January 4, 2016 08:49
Show Gist options
  • Save yjiro0403/784389cc679a3c23fc14 to your computer and use it in GitHub Desktop.
Save yjiro0403/784389cc679a3c23fc14 to your computer and use it in GitHub Desktop.
[D言語]UFCSを自分なりにメモ ref: http://qiita.com/yjiro0403/items/74b6eaf4c6cc2e4c2af1
//'a'をn回繰り返した配列を作る
char[] str = 'a'.repeat(n).array;
import std.file, std.string, std.algorithm, std.array;
//チェインメソッドを使わない処理
string[] text = splitLines(readText("text.txt"));
string[] hoge;
foreach(int i; text){
hoge[i] = text[i];
}
//最初にデータをすべて読み込んで一気に分割する方法
//対象ファイルが大きいと結構メモリを食うらしい
string[] text2 = splitLines(readText("text.txt")).map!strip.array;
//各行を順々に処理
auto strippedLines = File("text.txt").byLineCopy().map!strip.array;
import std.string, std.algorithm, std.array, std.conv;
//任意の要素をint型に変換して格納
//入力するときはスペースで区切る
//もっといいやり方あるよね...
string[] input = readln().split;
int num = input[0].to!int;
//intの配列に代入
int[] a = readln().split.map!(to!int).array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment