Comment detail
文字列の八方向検索 (Nested Flatten)皆さんと比べて長いんで、悔しくて短さに挑戦しました。まだまだ及びません…orz
see: 貧脚レーサーのサボり日記
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | //http://ja.doukaku.org/
//http://ja.doukaku.org/99/投稿用
using System;
using System.Collections.Generic;
namespace どう書く_org文字列の八方向検索 {
class Program {
static string search;
static List<string> list;
static void Main(string[] args) {
string sample = "リオウウリウ\nウオリウオリ\nオリリオリウ\nリリオオウオ";
search = "ウオリ";
char[] sp = new char[] { '\n' };
int width = sample.Split(sp)[0].Length;
int height = sample.Split(sp).Length;
list = new List<string>(sample.Split(sp));
for(int y = 0; y < list.Count; y++) { //縦ループ
for(int x = 0; x < list[y].Length; x++) { //横ループ
for(int dx = -1; dx <= 1; dx++) { //左右方向ループ
for(int dy = -1; dy <= 1; dy++) { //上下方向ループ -1は上、左 1は下、右を表す
try {
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 += "下";
}
Console.WriteLine("(" + x + "," + y + ")" + "," + directionStr);
}
} catch(ArgumentOutOfRangeException) { } catch(IndexOutOfRangeException) { }
}
}
}
}
Console.ReadLine();
}
}
}
|





あにす
#4603()
[
C#
]
Rating0/0=0.00
C#で。 動けばいいや的なコードです。
see: 貧脚レーサーのサボり日記
Rating0/0=0.00-0+
1 reply [ reply ]