Created
April 10, 2009 22:17
-
-
Save snuxoll/93333 to your computer and use it in GitHub Desktop.
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
using GLib; | |
namespace snuxoll { | |
class StdinReader : Object { | |
public StdinReader () { | |
} | |
public bool eof() { | |
return stdin.eof(); | |
} | |
public string? read_line() { | |
var line = new StringBuilder(); | |
var buffer = new char[1024]; | |
while ( ( !line.str.has_suffix ("\n") ) || this.eof() ) { | |
string chunk = stdin.gets(buffer); | |
if (chunk != null) { | |
line.append(chunk); | |
} else { | |
return null; | |
} | |
} | |
return line.str; | |
} | |
} | |
} |
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
using GLib; | |
using snuxoll; | |
class SumApplication : Object { | |
private uint64 total { get; set; } | |
public SumApplication() { | |
this.total = 0; | |
} | |
public void run() { | |
var reader = new StdinReader(); | |
while ( !stdin.eof() ) { | |
var line = reader.read_line(); | |
if ( line != null ) { | |
var nums = line.strip().split(" "); | |
foreach(string num in nums) { | |
this.total += num.to_int(); | |
} | |
} | |
} | |
stdout.printf("Grand Total: %llu\n", total); | |
} | |
static int main(string[] args) { | |
var app = new SumApplication(); | |
app.run(); | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment