package lianxi;
import java.io.*;
import java.lang.*;
class CardID{ 
  public static void main(String []args) throws IOException{
  
     System.out.println("请输入一个×××号码:");
    
     BufferedReader s= new BufferedReader(new InputStreamReader(System.in));
     String ww=s.readLine();
   
     if(ww.length()==15){
         System.out.println("该居民×××是旧的×××!");
         getInfof(ww);
         Convert(ww);
     }
    else if(ww.length()==18){
         System.out.println("该居民×××是新的×××!");
         getInfoe(ww);
     }
    else{
          System.out.println("该居民×××号码位数不符!");
     }
  }
  public static void getInfof(String s){
   
       String M=new String(s);
      
       int y=Integer.parseInt(M.substring(6,8));
       int m=Integer.parseInt(M.substring(8,10));
       int d=Integer.parseInt(M.substring(10,12));
      
       if (m<1 || m>12 || d<1 || d>31 || ((m==4 || m==6 || m==9 || m==11) && d>30) ||(m==2 && (((y+1900) % 4>0 && d>28) || d>29))){
       
        System.out.println("該居民身份證出生年月日错误!");
      }
        else{
         
            System.out.println("该居民出生地:"+M.substring(0,6));
            System.out.println("该居民出生时间为:"+y+"年"+m+"月"+d+"日");
         }
           
         int sex=Integer.parseInt(M.substring(14,15));
           
        if(sex%2==0){
        System.out.println("该居民为:女性");}
         else{
        System.out.println("该居民为:男性");
         }
    }
   public static void getInfoe(String s){
   
       String M=new String(s);
      
       int y=Integer.parseInt(M.substring(6,10));
       int m=Integer.parseInt(M.substring(10,12));
       int d=Integer.parseInt(M.substring(12,14));
      
       int[] xx={2,4,8, 5,10,9,7, 3,6,1,2, 4,8,5,10, 9,7};
       char[] yy={'1','0','X','9','8','7','6','5','4','3','2'};
      
       int mm=0;
      
       int[] gg = new int[18];
      
       if (y<1900 || m<1 || m>12 || d<1 || d>31 || ((m==4 || m==6 || m==9 || m==11) && d>30) ||(m==2 && ((y % 4>0 && d>28) || d>29))){
       
        System.out.println("該居民身份證出生年月日錯誤!");
       }
       else{
              System.out.println("该居民出生地:"+M.substring(0,6));
              System.out.println("该居民出生时间为:"+y+"年"+m+"月"+d+"日");}
              int sex=Integer.parseInt(M.substring(16,17));
       if(sex%2==0){       
        System.out.println("该居民为:女性");
      }
        else{       
        System.out.println("该居民为:男性");
        }
      
    for(int i=1;i<18;i++){
   int j = 17 - i;
       gg[i-1]=Integer.parseInt(M.substring(j,j+1));
    }
   
   /************************校验×××的真伪****************************/
   
        for(int i=0;i<17;i++){
          mm+=xx[i]*gg[i];
        }
     
         mm=mm%11;        
         char c= M.charAt(17);  
        
       if(c==yy[mm]){
           System.out.println("该居民×××是真的");
       }
       else{
           System.out.println("该居民×××是假的(校验码有误)");
       }
 }
  
  public static void Convert(String s)throws IOException{
 
        StringBuffer sad=new StringBuffer(s);          
               sad.insert(6,"19");     
              
       int[] xx={2,4,8, 5,10,9,7, 3,6,1,2, 4,8,5,10, 9,7};
       char[] yy={'1','0','X','9','8','7','6','5','4','3','2'};
       int mm=0;
       int[] gg = new int[18];
      
      for(int i=1;i<18;i++){
       int j = 17 - i;
          gg[i-1]=Integer.parseInt(sad.substring(j,j+1));
       }    
     
      for(int i=0;i<17;i++){      
       mm+=xx[i]*gg[i];}
          mm=mm%11;   
          System.out.println("该居民×××是新的×××"+sad+yy[mm]); 
      }       
}