我想解码我的加密数组。我们知道这些数字是1到9的编码。如果结果是1的编码,在子字符串中我们将不会有超过9个而只有,但我们有三个结果示例:
byte[][] A = new byte[][] { { 0, 1, 1, 1, 1, 0, 0, 0, 1 },
{ 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 },
{ 0, 1, 0, 0, 0, 0, 0, 1, 0 } }
结果:43211
byte[][] C = new byte[][] { {}, {},
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1 }, {},
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0 }, {}, { 1, 1 }, { 1 }, {}, { 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, {} };
结果:1233
byte[][] A = new byte[][] {
{ 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1 },
{ 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 } };
结果:332132
提前致谢!
答案 0 :(得分:0)
byte[][] A = new byte[][] {
{ 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1 },
{ 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 } };
String result = "";
int counter = 0;
for (byte[] arr : A) {
for (byte b : arr) {
if (b == 1)
counter++;
else {
if (counter > 0)
result += counter;
counter = 0;
}
}
}
if (counter > 0)
result += counter;
System.out.println(result);