每日编程(16)

1014 福尔摩斯的约会

每日编程(16)

import java.util.Scanner;


//PAT擅长玩文字游戏 ,一定要认真审题
//分别处理,两个字符串的对应位要相同,大写字母,相同字符(
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s1 = in.next();//表示不含空格
        String s2 = in.next();
        String s3 = in.next();
        String s4 = in.next();

        char[] ch1 = s1.toCharArray();
        char[] ch2 = s2.toCharArray();
        char[] ch3 = s3.toCharArray();
        char[] ch4 = s4.toCharArray();

        int i, j, count = 0;

        for (i = 0; i < ch1.length && i < ch2.length; i++) {
            if (ch1[i] >= 'A' && ch1[i] <= 'G' && ch1[i] == ch2[i] && count == 0) {
                switch (ch1[i] - 'A') {
                    case 0:
                        System.out.print("MON ");
                        break;
                    case 1:
                        System.out.print("TUE ");
                        break;
                    case 2:
                        System.out.print("WED ");
                        break;
                    case 3:
                        System.out.print("THU ");
                        break;
                    case 4:
                        System.out.print("FRI ");
                        break;
                    case 5:
                        System.out.print("SAT ");
                        break;
                    case 6:
                        System.out.print("SUN ");
                        break;

                }
                count++;

            } else if (ch1[i] >= '0' && ch1[i] <= '9' && ch1[i] == ch2[i] && count == 1 || ch1[i] >= 'A' && ch1[i] <= 'N' && ch1[i] == ch2[i] && count == 1) {
                if (ch1[i] >= '0' && ch1[i] <= '9') {
                    System.out.print("0" + ch1[i] + ":");
                } else if (ch1[i] >= 'A' && ch1[i] <= 'N') {
                    System.out.print((ch1[i] - 65 + 10) + ":");
                }

                count++;
            }

        }

        //后面两个字符串的处理
        for (j = 0; j < ch3.length && j < ch4.length; j++) {
            if ((ch3[j] >= 'a' && ch3[j] <= 'z' && ch3[j] == ch4[j]) || (ch3[j] >= 'A' && ch3[j] <= 'Z' && ch3[j] == ch4[j])) {
                if (j < 9) {
                    System.out.print("0" + j);
                } else {
                    System.out.print(j);
                }
            }
        }


    }
}

上一篇:java诗词横版--转为竖版


下一篇:String类实现replace()方法