#8534: JAVA解答


kkes0308 (kkes0308)

學校 : 國立臺中高級工業職業學校
編號 : 38469
來源 : [122.118.244.127]
最後登入時間 :
2014-02-03 16:35:05
a020. 身分證檢驗 | From: [111.253.196.215] | 發表日期 : 2014-01-12 10:49

package test;

import java.util.Scanner;

public class Mj {

public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
{
while (cin.hasNext()) {
String a = cin.nextLine();
String[] b = a.split("");
char[] c = b[1].toCharArray();
if (c[0] == 'A')
b[1] = "10";
if (c[0] == 'B')
b[1] = "11";
if (c[0] == 'C')
b[1] = "12";
if (c[0] == 'D')
b[1] = "13";
if (c[0] == 'E')
b[1] = "14";
if (c[0] == 'F')
b[1] = "15";
if (c[0] == 'G')
b[1] = "16";
if (c[0] == 'H')
b[1] = "17";
if (c[0] == 'I')
b[1] = "34";
if (c[0] == 'J')
b[1] = "18";
if (c[0] == 'K')
b[1] = "19";
if (c[0] == 'L')
b[1] = "20";
if (c[0] == 'M')
b[1] = "21";
if (c[0] == 'N')
b[1] = "22";
if (c[0] == 'O')
b[1] = "35";
if (c[0] == 'P')
b[1] = "23";
if (c[0] == 'Q')
b[1] = "24";
if (c[0] == 'R')
b[1] = "25";
if (c[0] == 'S')
b[1] = "26";
if (c[0] == 'T')
b[1] = "27";
if (c[0] == 'U')
b[1] = "28";
if (c[0] == 'V')
b[1] = "29";
if (c[0] == 'W')
b[1] = "32";
if (c[0] == 'X')
b[1] = "30";
if (c[0] == 'Y')
b[1] = "31";
if (c[0] == 'Z')
b[1] = "33";
int[] cd = new int[10];
for (int i = 0; i < 10; i++)
cd[i] = Integer.parseInt(b[i + 1]);
int test, e, f;
e = cd[0] / 10;
f = cd[0] % 10;
test = e + f * 9 + cd[9];
for (int i = 0; i < 9; i++)
test = test + (cd[i + 1] * (8 - i));
test = test % 10;
if (test == 0)
System.out.println("real");
else
System.out.println("fake");
}

}
}
}
 
#8535: Re:JAVA解答


caedmon_ng (Caedmon)

學校 :
編號 : 38525
來源 : [218.254.75.59]
最後登入時間 :
2014-05-18 22:22:26
a020. 身分證檢驗 | From: [218.254.75.59] | 發表日期 : 2014-01-12 15:12

很長...

我用陣列解滴

把英文字母變回ASCII

再利用條件式 把ASCII變題目要求的10~33

A~H的ASCII是65~72 則 減 55

I 的ASCII是73 則 34

所以程式碼可以簡潔些

 

 
ZeroJudge Forum