111,126
社区成员
发帖
与我相关
我的任务
分享
Point P1 = new Point(0, 0);
Point P2 = Point.Add(P1, new Size(1, 2));
MessageBox.Show(P2.ToString());
static void Main(string[] args)
{
string result = Calculte("G,1,2,3,4,5,6,7,8", 0);
Console.WriteLine(result);
result = Calculte("G,1,2,5,6;G,3,4,7,8", 0);
Console.WriteLine(result);
result = Calculte("G,1,2,5,6;G,3,4,7,8", 1);
Console.WriteLine(result);
result = Calculte("G,1;G,2,3,6,7;G,4;G,5;G,8", 0);
Console.WriteLine(result);
result = Calculte("G,1;G,2,3,6,7;G,4;G,5;G,8", 1);
Console.WriteLine(result);
result = Calculte("G,1;G,2,3,6,7;G,4;G,5;G,8", 2);
Console.WriteLine(result);
result = Calculte("G,1;G,2,3,6,7;G,4;G,5;G,8", 4);
Console.WriteLine(result);
Console.Read();
}
public static string Calculte(string str, int toWhere)
{
int[,] screen = new int[,] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 } };
string[] gs = str.Split(';');
if (gs.Length <= toWhere)
return "";
string[] blocks = gs[toWhere].Split(',');
int lx = 0, ly = 0,rx=0,ry=0;
GetXY(screen,out lx,out ly,int.Parse(blocks[1]));
GetXY(screen,out rx,out ry,int.Parse(blocks[blocks.Length - 1]));
return string.Format("x={0},y={1},width={2},height={3}", lx, ly, rx-lx+1, ry-ly+1);
}
public static void GetXY(int[,] screen,out int x,out int y,int n)
{
x = 1; y = 1;
bool found = false;
for (int i = 0; i < screen.GetLength(1); i++)
{
if (found == true)
break;
for (int j = 0; j < screen.GetLength(0); j++)
{
if (screen[j, i] == n)
{
x = i;
y = j;
found = true;
break;
}
}
}
}
……
dim X as integer=4
dim Y as integer=2
dim rows as string()=str.split(";") '你这里的分隔符好像是“;”(分号)吧!
'for each row as string in rows
' row=row.substring(2,row.length-2) '好像你的每个块标示前面都有一个“G,”,大概就2个字符
' dim columns as integer() =row.split(",")
' '这里自己先把columns里的每一个字符转换为数字,然后进行一个排序,按从小到大的顺序重新赋给columns,简单问题,自己解决!
' '排完序后执行以下代码,
' dim i as integer=0
' while i< columns.length
' if columns(i)>4 then
' 'return '这里返回你的新块
' end if
' i+=1
' end while
'next
dim row as string=rows(towhere-1)
row=row.substring(2,row.length-2) '好像你的每个块标示前面都有一个“G,”,大概就2个字符
dim columns as integer()=row.split(",")
'这里自己先把columns里的每一个字符转换为数字,然后进行一个排序,按从小到大的顺序重新赋给columns,简单问题,自己解决!
'排完序后执行以下代码,
dim cc as integer=1
if columns(0)>4 then
'return '这里返回你的towhere块的坐标以及长*宽,坐标就等于columns(0)的坐标,长*宽=(columns.length)* 1
else
dim i as integer=0
while i< columns.length
if columns(i)>4 then
return '这里返回你的towhere块的坐标以及长*宽,坐标就等于columns(0)的坐标,长*宽=cc* 2
else
cc+=1
end if
i+=1
end while
'这里返回你的towhere块的坐标以及长*宽,坐标就等于columns(0)的坐标,长*宽=cc* 1
end if
……