| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
JAVA RUNTIME ERROR测了很多数据,都没有问题,请大牛帮我看看吧,感激不尽
import java.util.Scanner;
public class Main {
private final static char[] ch = { 'F', 'E', 'D', 'C', 'B', 'A', '9', '8', '7',
'6', '5', '4', '3', '2', '1', '0' };
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
int x = scan.nextInt();
if(x == 546481141)
break;
char[] digit = { '-', '-', '-', '-', '-', '-', '-', '-' };
int n = 0;
for (int i = 0; i < 8; i++) {
int q = q(digit, i);
int a = 15 * p(15, (7 - i));
if(x > n + a) {
n += a;
continue;
}
int increm = p(15 - q, (7 - i));
int j = 1;
while (n + increm < x) {
n += increm;
j++;
}
findCh(digit, i, j);
}
boolean zero = true;
for (int i = 0; i < digit.length; i++)
if(digit[i] != '-') {
System.out.print(digit[i]);
zero = false;
}
if(zero)
System.out.println('0');
else
System.out.println();
x++;
}
}
private static void findCh(char[] digit, int n, int q) {
int flag = 0;
for (int j = 0; j < ch.length; j++) {
boolean find = false;
for (int i = 0; i < n; i++) {
if (digit[i] == ch[j]) {
find = true;
break;
}
}
if (!find) {
flag++;
if (flag == q) {
digit[n] = ch[j];
break;
}
}
}
}
//求排列组合P(n,r)
private static int p(int n, int r) {
int res = 1;
for (int i = 0; i < r; i++)
res *= (n - i);
return res;
}
private static int q(char[] digit, int j) {
int res = 0;
for(int i = 0; i < j; i ++) {
if(digit[i] == '-')
continue;
res ++;
}
return res;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator