L1-075 强迫症
小强在统计一个小区里居民的出生年月,但是发现大家填写的生日格式不统一,例如有的人写 199808
,有的人只写 9808
。有强迫症的小强请你写个程序,把所有人的出生年月都整理成 年年年年-月月
格式。对于那些只写了年份后两位的信息,我们默认小于 22
都是 20
开头的,其他都是 19
开头的。
输入格式:
输入在一行中给出一个出生年月,为一个 6 位或者 4 位数,题目保证是 1000 年 1 月到 2021 年 12 月之间的合法年月。
输出格式:
在一行中按标准格式 年年年年-月月
将输入的信息整理输出。
输入样例 1:
tex
9808
9808
输出样例 1:
tex
1998-08
1998-08
输入样例 2:
tex
0510
0510
输出样例 2:
tex
2005-10
2005-10
输入样例 3:
tex
196711
196711
输出样例 3:
tex
1967-11
1967-11
Solution:
java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s = in.readLine();
int length = s.length();
int num = Integer.parseInt(s);
int left = num / 100;
int right = num % 100;
if (length == 4) {
if (left < 22) System.out.printf("20%02d-%02d", left, right);
else System.out.printf("19%02d-%02d", left, right);
} else {
System.out.printf("%04d-%02d", left, right);
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s = in.readLine();
int length = s.length();
int num = Integer.parseInt(s);
int left = num / 100;
int right = num % 100;
if (length == 4) {
if (left < 22) System.out.printf("20%02d-%02d", left, right);
else System.out.printf("19%02d-%02d", left, right);
} else {
System.out.printf("%04d-%02d", left, right);
}
}
}