Friday, December 11, 2015

颠倒的价牌 蓝桥杯

http://blog.csdn.net/hortond/article/details/8887866

9 – 》 6
6-》 9
3 4 7 不可逆转。

-- find all candidate prices (its reverse - it [-200 , -300], [800, 900]), find a pair(pre sort), its sum is 558.

// 558 is not used - not work
``` public static void main(String[] args) {

DecimalFormat format = new DecimalFormat("0000");
String num = "";
for (int n = 1000; n < 10000; n++) {
num = format.format(n);
int numChange = change(num.toCharArray());
if(numChange<1000){
continue;
}
if(String.valueOf(numChange).contains("3")){
continue;
}// check 3, 4, 7 first
if(String.valueOf(numChange).contains("4")){
continue;
}
if ((n - numChange) >= 200 && (n - numChange) <= 300) {
System.out.println(n);

break;
}
}
}

private static int change(char[] charArray) {
for (int i = 0; i < charArray.length; i++) {

if (charArray[i] == '6') {
charArray[i] = '9';
} else if (charArray[i] == '9') {
charArray[i] = '6';
}
}
char[] Array2 = new char[charArray.length];
for (int i = 0; i < charArray.length; i++) {
Array2[i] = charArray[charArray.length-1-i];
}
String str  = String.valueOf(Array2);

return Integer.valueOf(str);
}
```

http://www.zhuangjingyang.com/%E9%A2%A0%E5%80%92%E7%9A%84%E4%BB%B7%E7%89%8C.html