You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
38 lines
1.0 KiB
1 year ago
|
const std = @import("std");
|
||
|
|
||
|
pub fn main() !void {
|
||
|
const stdout = std.io.getStdOut().writer();
|
||
|
|
||
|
const raw_in = std.io.getStdIn();
|
||
|
var buffered_reader = std.io.bufferedReader(raw_in.reader());
|
||
|
var reader = buffered_reader.reader();
|
||
|
|
||
|
var result: u32 = 0;
|
||
|
var line_buffer: [1000]u8 = undefined;
|
||
|
while (try reader.readUntilDelimiterOrEof(&line_buffer, '\n')) |line| {
|
||
|
var firstDigit: u8 = 0;
|
||
|
var lastDigit: u8 = 0;
|
||
|
for (0..line.len) |i| {
|
||
|
const char = line[i];
|
||
|
if (char >= '0' and char <= '9') {
|
||
|
firstDigit = char - '0';
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
for (0..line.len) |i| {
|
||
|
const index = line.len - i - 1;
|
||
|
const char = line[index];
|
||
|
if (char >= '0' and char <= '9') {
|
||
|
lastDigit = char - '0';
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
result += firstDigit * 10 + lastDigit;
|
||
|
}
|
||
|
try stdout.print(
|
||
|
"{d}\n",
|
||
|
.{result},
|
||
|
);
|
||
|
}
|