-
Notifications
You must be signed in to change notification settings - Fork 0
/
Input.cs
40 lines (35 loc) · 922 Bytes
/
Input.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.IO;
namespace NARDIAC
{
public abstract class Input
{
abstract public Word Read();
}
class ConsoleInput : FileInput
{
public ConsoleInput() : base(Console.In) { }
}
class FileInput : Input
{
readonly TextReader reader;
public FileInput(TextReader reader)
{
this.reader = reader;
}
override public Word Read() => new Word(Digit(), Digit(), Digit());
private byte Digit()
{
while (true)
{
int ch = reader.Read();
if(ch >= '0' && ch <= '9')
{
return (byte)(ch - '0');
}
if (ch == ' ' || ch == '\r' || ch == '\t' || ch == '\n') continue;
throw new InvalidDataException("Invalid character " + (char)ch);
}
}
}
}