Advent of Code Day 2 损坏校验和

解题语言不限Java

题目内容

As you walk through the door, a glowing humanoid shape yells in your direction. "You there! Your state appears to be idle. Come help us repair the corruption in this spreadsheet - if we take another millisecond, we'll have to display an hourglass cursor!"

当你通过门的时候,一个人形的火焰对你大喊“你来帮我们修复这个表格吗。如果我们用一毫秒来恢复这个表格,我们必须要一个滴漏光标”

The spreadsheet consists of rows of apparently-random numbers. To make sure the recovery process is on the right track, they need you to calculate the spreadsheet's checksum. For each row, determine the difference between the largest value and the smallest value; the checksum is the sum of all of these differences.

这个表格是由随机数字组成的。为了保证恢复过程顺利进行,要计算这个表格的校验和。校验和是每一行最大和最小值得差值的和。

5 1 9 5
7 5 3
2 4 6 8
The first row's largest and smallest values are 9 and 1, and their difference is 8.
第一行最大的数字是9,最小的是1,所以差值是8
The second row's largest and smallest values are 7 and 3, and their difference is 4.
第二行最大的数字是7,最小的是3,所以差值是4
The third row's difference is 6.
第三行的差值是6
In this example, the spreadsheet's checksum would be 8 + 4 + 6 = 18.
在这个例子里,电子表格的校验和是8+4+6=18

解题思路

将输入复制到文件
在读取循环中,同时计算单行数据的最大值和最小值
计算差值并加到buff里

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,934评论 0 23
  • 夜莺与猫阅读 276评论 0 0
  • 今天是训练第12天,时间过的好快,只剩下4天了。每一天都在忙碌充实的过着,有目标有意义的进行着我的每日任务,这样的...
    FAB伊颜阅读 455评论 0 0
  • 在我的窗前我们的楼前 在我们这栋楼与前栋楼之间 有一块并不算大的地段 长着两三棵会开花的树 还有特意撒种的品类也不...
    王根云阅读 242评论 0 4
  • 达者非远方, 内心暗向往, 三千日光城, 何时解行囊? 2017.6.17
    一团菌阅读 168评论 5 5