浙江大学PAT (Basic Level) Practice (中文)1014福尔摩斯的约会JAVA实现代码及分析
2019-03-15 13:24
609 查看
1014
福尔摩斯的约会
这道题需要注意的地方有以下几点:
①决定星期几的是前两个字符串的第一个相同的大写字母,注意是第一个大写的字母,小写不算。
②决定分钟数的是后两对字符串的第一个相同的字母所出现的位置,也就是它的下标位置,这里大小写字母均可以但是不可以是其他字符。
③小时和分钟的输出格式是两位输出,也就是说不足两位时要在前面加0补足位数之后进行输出。
具体实现代码如下:
import java.util.Scanner; public class Main { public static void main(String[] args) { char a[][]=new char[4][]; String temp; Scanner input=new Scanner(System.in); for(int i=0;i<4;i++) { temp=input.next(); a[i]=temp.toCharArray(); } printDayAndHour(a[0],a[1]); printMin(a[2],a[3]); } public static void printDayAndHour(char []a1,char[]a2) { int m=Math.min(a1.length,a2.length); boolean flag=false; for(int i=0;i<m;i++) { if(a1[i]==a2[i]) { if(!flag) { switch(a1[i]) { case 'A': { System.out.print("MON"+" "); flag=true; break; } case 'B': { System.out.print("TUE"+" "); flag=true; break; } case 'C': { System.out.print("WED"+" "); flag=true; break; } case 'D': { System.out.print("THU"+" "); flag=true; break; } case 'E': { System.out.print("FRI"+" "); flag=true; break; } case 'F': { System.out.print("SAT"+" "); flag=true; break; } case 'G': { System.out.print("SUN"+" "); flag=true; break; } } } else { if((a1[i] >= '0' && a1[i] <= '9') || (a1[i] >= 'A' && a1[i] <= 'N')) { if(a1[i] >= '0' && a1[i] <= '9') { System.out.printf("%02d:",a1[i]-'0');//格式化补零 } else { System.out.printf("%02d:",a1[i]-'A'+10);//格式化补零 } break; } } } } } public static void printMin(char []a3,char[]a4) { int m=Math.min(a3.length,a4.length); for(int i=0;i<m;i++) { if((a3[i]==a4[i])) { if((a3[i]>='a'&&a3[i]<='z')||(a3[i]>='A'&&a3[i]<='Z')) { String s=String.format("%02d", i);//格式化补零 System.out.print(s); break; } } } } }
相关文章推荐
- 浙江大学PAT (Basic Level) Practice (中文)1017A除以BJAVA实现代码及分析
- 浙江大学PAT (Basic Level) Practice (中文)1015德才论JAVA实现代码及分析
- 浙江大学PAT (Basic Level) Practice (中文)1018锤子剪刀布JAVA实现代码及分析
- 浙江大学PAT (Basic Level) Practice (中文)1016部分A+BJAVA实现代码及分析
- PAT (Basic Level) Practise (中文)1014.福尔摩斯的约会
- PAT (Basic Level) Practise (中文) 1014. 福尔摩斯的约会 (20)
- PAT (Basic Level) Practise (中文)1014. 福尔摩斯的约会 (20)
- PAT (Basic Level) Practise (中文)- 1014. 福尔摩斯的约会 (20)
- PAT (Basic Level) Practise (中文)1014. 福尔摩斯的约会 (20)
- PAT乙级真题及训练集 PAT (Basic Level) Practise (中文)1014. 福尔摩斯的约会
- PAT (Basic Level) Practice 1014 福尔摩斯的约会
- Pat(Basic Level)Practice--1014(福尔摩斯的约会)
- PAT BASIC LEVEL 1014. 福尔摩斯的约会 (20)
- PAT Basic Level 1014. 福尔摩斯的约会(20)
- PAT (Basic Level) Practise:1014. 福尔摩斯的约会
- PAT Basic 1014. 福尔摩斯的约会 (20)(C语言实现)
- PAT 乙级 (Basic Level) Practice (中文)1014
- PAT (Basic Level) Practise 1014. 福尔摩斯的约会 (20)
- 【C++】浙大PAT (Basic Level)1014. 福尔摩斯的约会 (20)
- 1014. 福尔摩斯的约会 (20)--PAT乙级真题-浙大PAT乙级真题java实现