42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
#include <cstdint>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
int main() {
|
|
std::fstream input("input");
|
|
std::string currentLine = "";
|
|
uint64_t totalJolt = 0, lineLength = 0;
|
|
while (std::getline(input, currentLine)) {
|
|
char mostSignificantDigit = '0', leastSignificantDigit = '0';
|
|
lineLength = currentLine.length();
|
|
for (uint16_t currentPosition = 0; currentPosition < lineLength;
|
|
currentPosition++) {
|
|
char digit = currentLine[currentPosition];
|
|
|
|
if (mostSignificantDigit < digit) {
|
|
// Since this is the last digit
|
|
if (currentPosition == lineLength - 1) {
|
|
leastSignificantDigit = digit;
|
|
continue;
|
|
}
|
|
|
|
// Otherwise business as usual
|
|
mostSignificantDigit = digit;
|
|
leastSignificantDigit = '0';
|
|
continue;
|
|
}
|
|
|
|
if (leastSignificantDigit < digit) {
|
|
leastSignificantDigit = digit;
|
|
}
|
|
}
|
|
|
|
// Just a simple char > uint conversion
|
|
totalJolt +=
|
|
(10 * (mostSignificantDigit - 48)) + (leastSignificantDigit - 48);
|
|
}
|
|
std::cout << totalJolt << "\n";
|
|
return 0;
|
|
}
|