[java]
public class BinaryCode {
public String[] decode(String message) {
int DEGIT = message.length();
int Q[] = new int[DEGIT];
for(int i=0; i
int P[] = new int[DEGIT];
String bin0="0", bin1="1";
P[0] = 0;
for(int i=0; i
P[i+1] = Q[i]-P[i];
else
P[i+1] = Q[i]-P[i]-P[i-1];
if( P[i+1] < 0) {
bin0="NONE";
break;
}
bin0 += ""+P[i+1];
}
if (DEGIT > 1)
bin0 = (Q[DEGIT-1] == P[DEGIT-2]+P[DEGIT-1]) ? bin0 : "NONE";
else
bin0 = (Q[DEGIT-1] == P[DEGIT-1]) ? bin0 : "NONE";
P[0] = 1;
for(int i=0; i
P[i+1] = Q[i]-P[i];
else
P[i+1] = Q[i]-P[i]-P[i-1];
if( P[i+1] < 0) {
bin1="NONE";
break;
}
bin1 += ""+P[i+1];
}
if (DEGIT > 1)
bin1 = (Q[DEGIT-1] == P[DEGIT-2]+P[DEGIT-1]) ? bin1 : "NONE";
else
bin1 = (Q[DEGIT-1] == P[DEGIT-1]) ? bin1 : "NONE";
return new String[] {bin0, bin1};
}
}
[/java]
0 件のコメント:
コメントを投稿