| ||||||||||
| 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 | |||||||||
Please help..!!I don't know why my algo is wrong...
Please help me...
Is there any special test case??
import java.io.*;
class Main {
public static int ISBN(String l, int index) {
int n = l.length();
int count = 0;
for (int i = 0; i < n; i ++) {
if (i == index)
continue;
if (l.charAt(i) == 'X')
count += 10 * (n - i);
else
count += (l.charAt(i) - 48) * (n - i);
}
return count;
}
public static int nextISBN(int sum, int index) {
if (sum % 11 == 0 && sum != 0)
return 0;
if (sum == 0)
return 0;
int tmp = 10 - index;
for (int i = 0; i <= 10; i ++) {
if ((sum + (i * tmp)) % 11 == 0)
return i;
}
return -1;
}
public static void main(String args[]) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuffer buffer = new StringBuffer();
String linea;
while ((linea = in.readLine()) != null) {
int index = linea.indexOf('?');
int tmp = ISBN(linea, index);
int r = nextISBN(tmp, index);
if (r == 10)
System.out.println('X');
else
System.out.println(r);
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator