#12263: java解答參考


qaz5678 (nonono)

學校 : 不指定學校
編號 : 66803
來源 : [36.229.217.72]
最後登入時間 :
2017-07-30 22:37:05
a020. 身分證檢驗 | From: [36.229.135.192] | 發表日期 : 2017-06-21 12:03

import java.util.Scanner;
public class Test03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

while(sc.hasNext()){
String id = sc.next();
int a = 0; //英文字母轉數字
char isId[] = new char[id.length()]; //把字串轉維字元
int n2[] = new int[id.length()]; //把除了第一個英文字母的數字放進int裡

for(int i = 0; i < id.length(); i++){ //把字串轉字元
isId[i] = id.charAt(i);
if(i >= 1){ //不包含英文字母放進n2裡
n2[i-1] = id.charAt(i)-'0'; //-字元'0' 回複成原數字
}
}


//字母轉數字
char[] check = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
int[] n1 ={ 10, 11, 12, 13, 14, 15, 16, 17, 34, 18, 19, 20, 21, 22, 35, 23, 24, 25, 26, 27, 28, 29, 32, 30,
31, 33 };

for(int i = 0; i < check.length; i++){
if(isId[0] == check[i]){
a = n1[i];
}
}
int firstNumber = a/10;
int secondNumber = a%10;

int q =firstNumber+secondNumber*9+n2[0]*8+n2[1]*7+n2[2]*6+n2[3]*5+n2[4]*4+n2[5]*3+n2[6]*2+n2[7]*1+n2[8];
if(q%10 == 0){
System.out.println("real");
}else{
System.out.println("fake");
}


}
}
}

 
#17836: Re:java解答參考


a43913072@gmail.com (陳芃)

學校 : 國立暨南國際大學
編號 : 86383
來源 : [219.68.215.178]
最後登入時間 :
2019-06-25 20:44:12
a020. 身分證檢驗 | From: [163.22.18.105] | 發表日期 : 2019-05-24 19:34

 

請問直接這樣寫可以嗎

public class a001{

    public static void main(String[] args) {

java.util.Scanner scanner = new java.util.Scanner(System.in);

String[] en= {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; 

    int[] ma= {10,11,12,13,14,15,16,17,34,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33};

    String[] input=new String[10];

    int ten,zero,all=0;

    for(int i=0;i<10;i++) {

        input[i]=scanner.next();

        for(int j=0;j<25;j++) {

            if(input[0]==en[j]) {

                ten=ma[j]/10;

                zero=ma[j]%10;

                all=ten+zero*9;

                System.out.print(all);

            } 

        }

    } 

    }

}

 
#17837: Re:java解答參考


a43913072@gmail.com (陳芃)

學校 : 國立暨南國際大學
編號 : 86383
來源 : [219.68.215.178]
最後登入時間 :
2019-06-25 20:44:12
a020. 身分證檢驗 | From: [163.22.18.105] | 發表日期 : 2019-05-24 19:35

import java.util.Scanner;
public class Test03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

while(sc.hasNext()){
String id = sc.next();
int a = 0; //英文字母轉數字
char isId[] = new char[id.length()]; //把字串轉維字元
int n2[] = new int[id.length()]; //把除了第一個英文字母的數字放進int裡

for(int i = 0; i < id.length(); i++){ //把字串轉字元
isId[i] = id.charAt(i);
if(i >= 1){ //不包含英文字母放進n2裡
n2[i-1] = id.charAt(i)-'0'; //-字元'0' 回複成原數字
}
}


//字母轉數字
char[] check = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
int[] n1 ={ 10, 11, 12, 13, 14, 15, 16, 17, 34, 18, 19, 20, 21, 22, 35, 23, 24, 25, 26, 27, 28, 29, 32, 30,
31, 33 };

for(int i = 0; i < check.length; i++){
if(isId[0] == check[i]){
a = n1[i];
}
}
int firstNumber = a/10;
int secondNumber = a%10;

int q =firstNumber+secondNumber*9+n2[0]*8+n2[1]*7+n2[2]*6+n2[3]*5+n2[4]*4+n2[5]*3+n2[6]*2+n2[7]*1+n2[8];
if(q%10 == 0){
System.out.println("real");
}else{
System.out.println("fake");
}


}
}
}

轉換型別看不懂


 

 
ZeroJudge Forum