あにす #4645(2007/12/06 13:20 GMT) [ C# ] Rating0/0=0.00
"リリリ"の様な同じ文字が連続した文字列を検索すると不具合が出たので修正。 ついでに、何処まで行数を減らせるかテスト。可読性は二の次。
see: 貧脚レーサーのサボり日記
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
class Program { //http://ja.doukaku.org/99/投稿用 static void Main(string[] args) { string search = "ウオリ"; System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(new string[] { "リオウウリウ", "ウオリウオリ", "オリリオリウ", "リリオオウオ" }); int width = list[0].Length; int height = list.Count; for(int y = 0; y < list.Count; y++) { //縦ループ for(int x = 0; x < list[y].Length; x++) { //横ループ for(int dx = -1; dx <= 1; dx++) { //左右方向ループ -1は上、左 1は下、右を表す for(int dy = -1; dy <= 1; dy = dy + (dx == 0 ? 2 : 1)) { //上下方向ループ try { //dxが0の時はdyを2ステップして、両方が0にならないようにする string strb = ""; for(int i = 0; i < search.Length; i++) { //iは移動量 strb += list[y + i * dy][x + i * dx];} //移動方向をdy,dxで乗算することで反転 if(search == strb) { string directionStr = ""; if(dx < 0) directionStr += "左"; else if(dx > 0) directionStr += "右"; if(dy < 0) directionStr += "上"; else if(dy > 0) directionStr += "下"; System.Console.WriteLine("(" + x + "," + y + ")" + "," + directionStr);} } catch(System.ArgumentOutOfRangeException) { } catch(System.IndexOutOfRangeException) { }}}}} System.Console.ReadLine();}}
Rating0/0=0.00-0+
1 reply [ reply ]
あにす
#4645()
[
C#
]
Rating0/0=0.00
"リリリ"の様な同じ文字が連続した文字列を検索すると不具合が出たので修正。 ついでに、何処まで行数を減らせるかテスト。可読性は二の次。
see: 貧脚レーサーのサボり日記
Rating0/0=0.00-0+
1 reply [ reply ]