Original title link: http://lx.lanqiao.cn/problem.page?gpid=T325
Welcome to my Blue Bridge Cup OJ Problem Solution~ https://blog.csdn.net/richenyunqi/article/details/80192062
Algorithms improve ID number upgrade
Time limit: 1.0s Memory limit: 256.0MB
Problem Description
Beginning on October 1, 1999, the number of national identity cards has been increased from 15 digits to 18 digits. (Introduction to the 18-digit ID number). The upgrade method is:
1. Change the year in the 15-digit ID number from 2 digits (7, 8 digits) to four digits.
2. Finally add a verification code. Calculation scheme of verification code:
Multiply the first 17 digits by the corresponding coefficients (7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2) and add them up, then divide by 11 to get the remainder, 0-10 correspond to 1 0 x 9 8 7 6 5 4 3 2.
Please write a program, the user inputs a 15-digit ID number, and the program generates an 18-digit ID number. Assume that the four-digit year of all ID cards to be upgraded is 19××
1. Change the year in the 15-digit ID number from 2 digits (7, 8 digits) to four digits.
2. Finally add a verification code. Calculation scheme of verification code:
Multiply the first 17 digits by the corresponding coefficients (7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2) and add them up, then divide by 11 to get the remainder, 0-10 correspond to 1 0 x 9 8 7 6 5 4 3 2.
Please write a program, the user inputs a 15-digit ID number, and the program generates an 18-digit ID number. Assume that the four-digit year of all ID cards to be upgraded is 19××
input format
A 15-digit string, as the ID number
output format
An 18-bit string, as the upgraded ID number
sample input
110105491231002
Sample output
11010519491231002x
Data size and conventions
No need to judge whether the input 15-digit string is reasonable
java code:
import java.util. *; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s=in.nextLine(); char a[]={ '1','0' ,'x' ,'9' ,'8' ,'7' ,'6' ,'5' ,'4' ,'3' ,'2' }; int b[]={ 7 ,9 ,10, 5, 8 ,4, 6 ,3, 7 ,9 ,10 ,5, 8, 4 ,2 }; int ss=0; for(int i=0;i<s.length();++i){ ss+=(s.charAt(i)-48)*b[i]; } ss+=1*2+9; char c=a[ss%11]; for(int i=0;i<6;++i){ System.out.print(s.charAt(i)); } System.out.print("19"); for(int i=6;i<s.length();++i){ System.out.print(s.charAt(i)); } System.out.print(c); } }