-
个人简介
I'd rather believe l'm a muggle than that there's no magic in the world.
import java.util.Timer; import java.util.TimerTask; import static java.lang.Math.min; public class Love { public static void main(String[] args){ var i = new Person("I"); var you = new Person("you"); Timer timer = new Timer(); TimerTask task = new TimerTask() { @Override public void run() { i.love(you); } }; timer.schedule(task, 0, 1000); } } class Person { private final String name; private final long begin=System.currentTimeMillis(); public Person(String name){ this.name = name; } public void love(Person p) { if (p == null) { System.out.println("There will never be someone to love you!"); return; } long time = (System.currentTimeMillis() - min(begin,p.begin)); long centuries = time / (1000L * 60L * 60L * 24L * 36525L); time -= centuries * (1000L * 60L * 60L * 24L * 36525L); long years = time / (1000L * 60L * 60L * 24L * 365L); time -= years * (1000L * 60L * 60L * 24L * 365L); long days = time / (1000L * 60L * 60L * 24L); time -= days * (1000L * 60L * 60L * 24L); long hours = time / (1000L * 60L * 60L); time -= hours * (1000L * 60L * 60L); long minutes = time / (1000L * 60L); time -= minutes * (1000L * 60L); long seconds = time / 1000L; StringBuilder unit = new StringBuilder(); if (centuries > 0) unit.append(" ").append(centuries).append(" century").append(centuries > 1 ? "s" : ""); if (years > 0) unit.append(" ").append(years).append(" year").append(years > 1 ? "s" : ""); if (days > 0) unit.append(" ").append(days).append(" day").append(days > 1 ? "s" : ""); if (hours > 0) unit.append(" ").append(hours).append(" hour").append(hours > 1 ? "s" : ""); if (minutes > 0) unit.append(" ").append(minutes).append(" minute").append(minutes > 1 ? "s" : ""); if (seconds > 0 || unit.length() == 0) unit.append(" ").append(seconds).append(" second").append(seconds > 1 ? "s" : ""); String verb = (name.equalsIgnoreCase("they") || name.equalsIgnoreCase("I") || name.equalsIgnoreCase("you")) ? "have loved" : "has loved"; System.out.printf("%s %s %s for%s.\n", name.toUpperCase(), verb, p.name.toUpperCase(), unit); } }
-
通过的题目
- 429
- 430
- 436
- 459
- 483
- 484
- 554
- 561
- 562
- 593
- 594
- 595
- 596
- 597
- 599
- 600
- 602
- 603
- 604
- 605
- 606
- 630
- 646
- 650
- 661
- 668
- 680
- 681
- 693
- 694
- 707
- 761
- 790
- 828
- 829
- 831
- 832
- 834
- 864
- 883
- 917
- 941
- 1023
- 1032
- 1034
- 1040
- 1044
- 1045
- 1047
- 1064
- 1074
- 1078
- 1100
- 1123
- 1132
- 1160
- 1161
- 1162
- 1166
- 1167
- 1178
- 1179
- 1180
- 1184
- 1210
- 1213
- 1214
- 1215
- 1216
- 1217
- 1218
- 1219
- 1220
- 1221
- 1222
- 1223
- 1224
- 1225
- 1226
- 1227
- 1228
- 1229
- 1230
- 1231
- 1232
- 1233
- 1234
- 1235
- 1236
- 1237
- 1238
- 1239
- 1240
- 1241
- 1242
- 1243
- 1244
- 1245
- 1246
- 1247
- 1248
- 1249
- 1250
- 1251
- 1252
- 1253
- 1254
- 1255
- 1256
- 1257
- 1259
- 1261
- 1262
- 1263
- 1264
- 1268
- 1270
- 1271
- 1273
- 1278
- 1285
- 1298
- 1304
- 1305
- 1308
- 1311
- 1321
- 1330
- 1337
- 1353
- 1367
- 1369
- 1388
- 1476
- 1480
- 1494
- 1495
- 1496
- 1497
- 1498
- 1501
- 1524
- 1529
- 1549
- 1551
- 1552
- 1553
- 1555
- 1556
- 1558
- P1559
- P1560
- P1562
- 1563
- 1564
- 1566
- 1585
-
最近活动
-
最近编写的题解
题目标签
- 基础问题
- 33
- 分支问题
- 33
- 循环语句
- 23
- 字符串
- 21
- 需要找规律的循环
- 21
- 简单循环
- 20
- 嵌套循环
- 15
- 条件分支
- 13
- 数组问题
- 12
- 进制转换
- 10
- 搜索
- 10
- 递归
- 10
- 动态规划
- 9
- 二维数组
- 8
- 深搜
- 8
- 图结构
- 8
- 树结构
- 7
- 回溯
- 6
- 图论
- 6
- 高精度算法
- 5