Thread overview | |||||
---|---|---|---|---|---|
|
February 16, 2015 A specifier readf() for BigInt | ||||
---|---|---|---|---|
| ||||
Hi. And how to read Data from the input stream? import std.stdio; import std.bigint; void main() { BigInt n; readf(" %?", &n); writeln(n); } |
February 17, 2015 Re: A specifier readf() for BigInt | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis Ritchie | On Monday, 16 February 2015 at 19:52:20 UTC, Dennis Ritchie wrote:
> Hi.
> And how to read Data from the input stream?
>
> import std.stdio;
> import std.bigint;
>
> void main() {
>
> BigInt n;
>
> readf(" %?", &n);
>
> writeln(n);
> }
The readf function does not seem to support reading BigInts directly.
However, you can read a string and construct a BigInt from it, either by std.conv.to or directly invoking the constructor:
import std.algorithm, std.bigint, std.conv, std.stdio, std.string;
void main () {
// read a line of space-separated BigInts and print their sum:
readln.split.map !(to!BigInt).sum.writeln;
// read a line containing one BigInt and print it squared:
auto s = BigInt (readln.strip);
writeln (s ^^ 2);
}
|
February 17, 2015 Re: A specifier readf() for BigInt | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ivan Kazmenko | On Tuesday, 17 February 2015 at 07:20:19 UTC, Ivan Kazmenko wrote:
>
> The readf function does not seem to support reading BigInts directly.
>
> However, you can read a string and construct a BigInt from it, either by std.conv.to or directly invoking the constructor:
>
> import std.algorithm, std.bigint, std.conv, std.stdio, std.string;
>
> void main () {
> // read a line of space-separated BigInts and print their sum:
> readln.split.map !(to!BigInt).sum.writeln;
> // read a line containing one BigInt and print it squared:
> auto s = BigInt (readln.strip);
> writeln (s ^^ 2);
> }
Thanks.
|
Copyright © 1999-2021 by the D Language Foundation