|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?注册帐号
x
最近写了一个算法,要求 二维数组 里面的 数据,向右向下 靠拢。
如图1,2
上图是 x=6 y=7的一个42格子的 数组。
首先 初始化数据 和 字符串数组,放单例里面。类似 如下
string GModel.getInstance.playModel.formation =\"123001200....\"
string [] GModel.getInstance.playModel.formations=GModel.getInstance.playModel.formation.Split(\'\');
然后是 算法
[mw_shl_code=csharptrue] public static string OnSetArrSort(int x int y)
{
int ii = 0;
string FF = \"\";
int j1 = 0;
int j3 = 0;
for (int i = 0; i < x; i++)
{
for (int j = 0; j < y; j++)
{
if (j == 0)
{
for (int k = 0; k < j3; k++)
{
FF += \"0\";
}
j3 = 0;
j1 = 0;
}
if (GModel.getInstance.playModel.formations[ii] != \"0\")
{
FF += GModel.getInstance.playModel.formations[ii] + \"\";
}
else
{
j1++;
j3++;
if (j1 == y)
{
j3 = 0;
}
}
ii++;
}
}
int flenth = (FF.Length) / 2;
for (int h = 0; h < (x * y - flenth); h++)
{
FF += \"0\";
}
return FF.Substring(0 x * y * 2 - 1);
}[/mw_shl_code]
调用 类似 string[] ff = ArrSort.OnSetArrSort(6 7).Split(\'\');
|
|