os:看了下别人写的代码太乱 干脆自己写
import java.util.Scanner;
/*
总体思路:
接收四行参数
通过index指针遍历字符串
时间复杂度O(1)
*/
public class Main{
//打表 为了拿到日期对应的字符串
static String[] tableDay={"MON","TUE","WED","THU","FRI","SAT","SUN"};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a=sc.nextLine();
String b=sc.nextLine();
String c=sc.nextLine();
String d=sc.nextLine();
int i=0;
StringBuffer stb=new StringBuffer();//存储拼接字符串
//时间
while (i<a.length()&&i<b.length()){
char temp = a.charAt(i);
//条件很苛刻 必须在A-G之间
if (temp>='A'&&temp<='G'&&a.charAt(i)==b.charAt(i)){
stb.append(tableDay[temp-65]+" ");
i++;
break;
//跳出循环
}
i++;
}
//小时
while (i<a.length()&&i<b.length()){
char temp=a.charAt(i);
if (temp==b.charAt(i)){
//分情况是为了更好拼接字符串
if (temp>='A'&&temp<='N'){
stb.append(temp-55+":");
break;
}
if (temp<='9'&&temp>='0'){
stb.append("0"+temp+":");
break;
}
}
i++;
}
//分钟
i=0;
while (i<c.length()&&i<d.length()){
char temp=c.charAt(i);
//注意条件 A-z
if (temp==d.charAt(i)&&temp>='A'&&temp<='z'){
//分情况是为了更好拼接字符串
if (i<=9) stb.append("0" + i);
if (i>=10) stb.append(i);
break;
}
i++;
}
System.out.print(stb);
sc.close();
}
}
任何问题可留言评论区!
2022年11月3日