-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24fad29
commit 59dcf5b
Showing
3 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
fn read_char() -> I64 { | ||
let mut v = 0; | ||
let mut res = 0; | ||
asm { | ||
subq $8 %RSP // allocate stack space for reading char | ||
movq $0 %RAX // read | ||
movq $0 %RDI // stdin | ||
movq %RSP %RSI // put read char at top of stack | ||
movq $1 %RDX // read 1 byte | ||
syscall 4 // arity of 4 | ||
movq %RAX {res} // result of system call | ||
popq {v} // pop read char | ||
}; | ||
if res == 0 { | ||
return res | ||
}; | ||
v | ||
} | ||
|
||
fn main() { | ||
let ASCII_NEWLINE = 10; | ||
let ASCII_ZERO = 48; | ||
let ASCII_NULL = 0; | ||
|
||
let mut next = read_char(); | ||
|
||
let mut best = 0; | ||
let mut sum = 0; | ||
let mut current = 0; | ||
let mut last_was_newline = false; | ||
|
||
while next != ASCII_NULL { | ||
if next == ASCII_NEWLINE { | ||
if last_was_newline { | ||
// Found empty line | ||
if sum > best { | ||
best = sum; | ||
}; | ||
sum = 0; | ||
} else { | ||
last_was_newline = true; | ||
sum = sum + current; | ||
current = 0; | ||
} | ||
} else { | ||
last_was_newline = false; | ||
current = current * 10 + next - ASCII_ZERO; | ||
}; | ||
next = read_char(); | ||
}; | ||
print(best); | ||
} |