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,921評論 0 23
  • 夜鶯與貓閱讀 276評論 0 0
  • 今天是訓練第12天,時間過的好快,只剩下4天了。每一天都在忙碌充實的過著,有目標有意義的進行著我的每日任務,這樣的...
    FAB伊顏閱讀 455評論 0 0
  • 在我的窗前我們的樓前 在我們這棟樓與前棟樓之間 有一塊并不算大的地段 長著兩三棵會開花的樹 還有特意撒種的品類也不...
    王根云閱讀 242評論 0 4
  • 達者非遠方, 內心暗向往, 三千日光城, 何時解行囊? 2017.6.17
    一團菌閱讀 168評論 5 5