4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LINQで2つの文字列を先頭から結合

Posted at

言語処理100本ノック2015の下記問題を解いてみました。

「パトカー」+「タクシー」=「パタトクカシーー」
「パトカー」+「タクシー」の文字を先頭から交互に連結して文字列「パタトクカシーー」を得よ.

	var text1 = "パトカー";
	var text2 = "タクシー";
	var count = 0;
	var dicText1 = text1.ToDictionary(x => count++, x => x);
	count = 0;
	var dicText2 = text2.ToDictionary(x => count++, x => x);
    var result = string.Concat(dicText1.Concat(dicText2).Dump().OrderBy(x => x.Key).Dump().Select(x => x.Value)).Dump();

ソートが多少怪しいですが、まぁ動きます。
LINQを用いた文字列結合、どう書くのが良いのか難しいです。

4
5
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?