PAT乙级(Basic Level)真题 >福尔摩斯的约会 (Java记录)

import java.math.*;
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner cin = new Scanner(System.in);
        String str[];
        str = new String[4];//如果定义一维的直接为String()
        for(int i = 0;i < 4;++ i)
            str[i] = cin.next();
        int tmp = 0;
        for(int i = 0,j = 0;i<str[0].length()&&j<str[1].length();++ j,++ i){
            char aa=str[0].charAt(i);
            char bb=str[1].charAt(j) ;
            if(aa==bb && tmp==0){
                if(aa>='A'&&aa<='Z'){
                    if(aa=='A'){
                        System.out.print("MON ");
                    }
                    else if(aa=='B'){
                        System.out.print("TUE ");
                    }
                    else if(aa=='C'){
                        System.out.print("WED ");
                    }
                    else if(aa=='D'){
                        System.out.print("THU ");
                    }
                    else if(aa=='E'){
                        System.out.print("FRI ");
                    }
                    else if(aa=='F'){
                        System.out.print("SAT ");
                    }
                    else if(aa=='G'){
                        System.out.print("SUN ");
                    }
                    ++tmp;
                }

            }
            else if(aa==bb&&tmp==1){
                if( (aa>='0'&&aa<='9')){
                    System.out.print("0");
                    System.out.print(aa);++tmp;
                }
                else if(aa>='A'&&aa<='N'){
                    int t = aa-'A'+1;
                    System.out.print(t+9);++tmp;
                }

            }

        }
        int i,j,now=0;

        for( i = 0,j = 0;i<str[3].length()&&j<str[2].length();++ j,++ i){
            char aa = str[3].charAt(i);
            char bb = str[2].charAt(j);
            if( (aa>='A'&&aa<='Z')||(aa>='a'&&aa<='z')&&(bb>='A'&&bb<='Z')||(bb>='a'&&bb<='z') ){
                now++;
                if(aa==bb){
                    if(now<9){
                        System.out.print(":0");
                        System.out.println(now);break;
                    }
                    else{
                        System.out.print(":");
                        System.out.println(now);break;
                    }
                }
            }
        }
        cin.close();
    }

}

你可能感兴趣的:(java,String,basic)