-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.java
More file actions
116 lines (112 loc) · 2.71 KB
/
Input.java
File metadata and controls
116 lines (112 loc) · 2.71 KB
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
import java.io.*;
public class Input
{
private File f;
private FileInputStream fis;
private int buf;
private boolean ok=true;
public Input(String fileName)
{
try{
File f=new File(fileName);
fis=new FileInputStream(f);
buf=fis.read();
}catch(IOException ioe){
System.out.println("arxeio Input-fails1");
ok=false;
}
}
void close(){
if(fis!=null){
try{fis.close();}catch(IOException ioe){ok=false;}
}
}
int readInt(){
int x;
boolean neg=false;
while (Character.isWhitespace((char)buf)){nextChar();}
if(buf=='-'){
neg=true;
nextChar();
}
if(!Character.isDigit((char)buf)){
ok=false;
return 0;
}
x=buf-'0';
while( nextChar() && (Character.isDigit((char)buf)) ){
x=10*x+(buf-'0');
}
return(neg ? -x : x);
}
float readFloat(){
float x;
int nDec=-1;
boolean neg=false;
while(Character.isWhitespace((char)buf)){nextChar();}
if(buf=='-'){
neg=true;
nextChar();
}
if(buf=='.'){
nDec=0;
nextChar();
}
if(!Character.isDigit((char)buf)){
ok=false;
return 0;
}
x=buf-'0';
while(nextChar() && (Character.isDigit((char)buf) || (nDec==-1 && buf=='.'))){
if (buf =='.'){
nDec=0;
}else{
x=10*x+(buf-'0');
if (nDec>=0){
nDec++;
}
}
}
while(nDec>0){
x*=0.1;
nDec--;
}
if (buf=='e' || buf=='E'){
nextChar();
int exp=readInt();
if(!fails()){
while(exp>0){
x*=0.1;
exp++;
}
while(exp>0){
x*=10;
exp--;
}
}
}
return(neg ? -x : x);
}
char readChar(){
char ch=(char)buf;
nextChar();
return ch;
}
boolean eof(){return !ok && buf<0;}
boolean fails(){
return !ok;
}
void clear(){ok=true;}
private boolean nextChar(){
if(buf<0){
ok=false;
}else{
try{
buf=fis.read();
}catch(IOException ioe){
ok=false;
}
}
return ok;
}
}