-
Notifications
You must be signed in to change notification settings - Fork 0
/
Read.cs
130 lines (109 loc) · 3.29 KB
/
Read.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.IO;
using System.Globalization;
namespace Input {
public static class Read {
static string line;
static int pos;
static StreamReader file = null;
public static void UseFile(string name) {
file = new StreamReader(name);
line = null;
}
public static void UseInput(string input) {
line = input;
pos = 0;
}
static string GetLine() {
if (file != null) {
string l = file.ReadLine();
if (file.EndOfStream) {
file.Close();
file = null;
}
return l;
}
return Console.ReadLine();
}
static char Next() {
if (line == null || pos >= line.Length) {
line = GetLine();
pos = -1;
}
pos++;
return Last();
}
static char Last() {
if (line == null)
Next();
if (pos >= line.Length)
return '\n';
return line[pos];
}
public static string IntegerString() {
while (!char.IsDigit(Last()) && Last() != '-')
Next();
string num = new string(Last(), 1);
while (char.IsDigit(Next())) {
num += Last();
}
return num;
}
public static long Long() {
return long.Parse(IntegerString());
}
public static int Int() {
return int.Parse(IntegerString());
}
public static string FloatString() {
while (!char.IsDigit(Last()) && Last() != '-')
Next();
string num = new string(Last(), 1);
bool dot = false;
while (char.IsDigit(Next()) || (!dot && (Last() == '.' || Last() == ','))) {
dot |= !char.IsDigit(Last());
num += Last();
}
return num;
}
public static double Double() {
return double.Parse(FloatString().Replace(',', '.'), CultureInfo.InvariantCulture);
}
public static float Float() {
return float.Parse(FloatString().Replace(',', '.'), CultureInfo.InvariantCulture);
}
public static char Char() {
while (char.IsWhiteSpace(Last()))
Next();
char ret = Last();
Next();
return ret;
}
public static string String() {
while (char.IsWhiteSpace(Last()))
Next();
string ret = new string(Last(), 1);
while (!char.IsWhiteSpace(Next()))
ret += Last();
return ret;
}
public static int To(out int a) {
return a = Int();
}
public static long To(out long a) {
return a = Long();
}
public static char To(out char a) {
return a = Char();
}
public static string To(out string a) {
return a = String();
}
public static double To(out double a) {
return a = Double();
}
public static float To(out float a) {
return a = Float();
}
}
}