黑客情人节

好无(xiang)聊(ni)就写了个小程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.util.Scanner;

/**
* 黑客情人节
* @author 比心
*
*/
public class Ta {

//forvevr love
private static int FORVEVR_LOVE = 1314;

public static void main(String[] args) {
Ta zhou = new Ta();

Scanner in = new Scanner(System.in);

/* int year = in.nextInt();
int start = in.nextInt();
int end = in.nextInt();

zhou.forvevrLove(year, start, end);*/

zhou.forvevrLove(2017, 2, 108);
}



private void forvevrLove(int year , int start , int end){

int[] date = leapYear(year);

for(int i = 1 ; i < date.length ; i++){
for(int j = 1 ; j <= date[i] ; j++){
for(int k = start ; k <= end ; k++){
String number = String.valueOf(i)+
String.valueOf(j > 9 ? j :"0"+String.valueOf(j));
if(sumTao(number , k) == FORVEVR_LOVE){
System.out.println(i+"月"+j+"日是"+k+"进制的情人节");
}
}
}
}




}


private int sumTao(String number , int sys){

int n = number.length();
int[] temp = new int[n];

for(int i = 0 ; i < n ; i++){
temp[i] = Integer.parseInt(String.valueOf(number.charAt(i)));
}

int sum = 0;
for(int i = 0 ; i < n ; i++){
sum += temp[i]*Math.pow(sys, temp.length-i-1);
}

return sum;


}


private int[] leapYear(int year){

int flag = 0;
if(year%400 == 0 || year%4 == 0 && year%100 == 0){
flag=flag+1;//闰年二月多一天
}

int[] date = new int[13];

for(int i = 1 ; i < 13 ; i++){
if(i==1 || i==3 || i==5 || i==7 || i==8 || i==10 || i==12){
date[i] = 31;
continue;
}
if(i==4 || i==6 || i==9 || i==11){
date[i] = 30;
continue;
}
if(i==2){
date[i]=28+flag;
}
}

return date;
}


}

输出结果
4月10日是18进制的情人节
5月22日是16进制的情人节
9月16日是12进制的情人节