using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
/**
* Don't let the machines win. You are humanity's last hope...
**/
class Player
{
static void Main(string[] args)
{
int width = int.Parse(Console.ReadLine()); // the number of cells on the X axis
int height = int.Parse(Console.ReadLine()); // the number of cells on the Y axis
string[,] P = new string[height,width];
int x1=0,x2=0,x3=0;
int y1=0,y2=0,y3=0;
for (int i = 0; i < height; i++)
{
string line = Console.ReadLine(); // width characters, each either 0 or .
for(int j =0;j<width;j++)
{
P[i,j]=line.Substring(j,1);
}
}
// Write an action using Console.WriteLine()
// To debug: Console.Error.WriteLine("Debug messages...");
for(int i =0;i<height;i++)
{
for(int j =0;j<width;j++)
{
if(P[i,j]=="0")//x1,y1
{
x1=j;
y1=i;
}
else
{
x1=-1;
y1=-1;
}
int k =0;//x2,y2
x2=j+1;
y2=i;
do
{
if(j+k==width-1)
{
x2=-1;
y2=-1;
break;
}
k++;
x2=j+k;
y2=i;
}while(P[i,j+k] != "0");
int n=0;//x3,y3
x3=j;
y3=i+1;
do
{
if(i+n == height-1)
{
x3=-1;
y3=-1;
break;
}
n++;
x3=j;
y3=i+n;
}while(P[i+n,j] !="0");
if(x1 != -1)//x1min =0
{
Console.WriteLine("{0} {1} {2} {3} {4} {5}",x1,y1,x2,y2,x3,y3);
}
}
}
// Three coordinates: a node, its right neighbor, its bottom neighbor
}
}
整了两天,但这个代码嵌套太多,极其辣鸡
最早嵌套的太多,输出时间太长,改用while,但是会导致数组index溢出
后来改用do...while循环就解决了,虽然还是很繁琐
看了别人的也不太看得懂,加油吧