Advent of Code Day 2 损坏校验和

解题语言不限Java

  • Advent of Code Day 1 逆向验证码
  • Advent of Code Day 2 损坏校验和
  • Advent of Code Day 3 螺旋内存
  • Advent of Code Day 4 高熵密码
  • Advevnt of Code Day 5 曲折的蹦床迷宫
  • Advent of Code Day 6 内存重分配
  • Advent of Code Day 7 递归马戏团
  • Advent of Code Day 8 注册表爱好者
  • Advent of Code Day 9 流处理
  • Advent of Code Day 10 结哈希
  • Advent of Code Day 11 六边形迷宫

题目内容

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里

你可能感兴趣的:(Advent of Code Day 2 损坏校验和)