-
Notifications
You must be signed in to change notification settings - Fork 0
/
nonogramReader.h
91 lines (86 loc) · 2.25 KB
/
nonogramReader.h
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
#include <cstdio>
#include <cstdlib>
#include <string>
#include <new>
#include "board.h"
class NonogramInputReader{
public:
int problemNum;
FILE* f;
int r, c;
vector< vector<Limit> > lim_row;
vector< vector<Limit> > lim_col;
int size;
NonogramInputReader(FILE* p, int size){
f = p;
this->size = size;
}
void readInputAndGetBoard(Board *b, char* name, bool isTour){
if(isTour){
readInput_Tourament();//it can be changed
} else {
readInput();
}
initBoard(b, name);
}
private:
void initBoard(Board *b, char* name){
b->init(r, c, lim_row, lim_col, name, problemNum);
}
void readInput_Tourament(){
char in[10000];//I think it's big enough
char *ptr;
r = size; c = size;
if(fscanf(f, "$%d", &problemNum) != 1)
return;
lim_row.clear(); lim_col.clear();
lim_row.resize(r); lim_col.resize(c);
ptr = fgets(in, 10000, f);//dumb
for(int i = 0; i < c; i++){
ptr = fgets(in, 10000, f);
char *p;
p = strtok(in, " \t");
while(p != NULL){
lim_col[i].push_back(ColLimit(atoi(p)));
p = strtok(NULL, " \t");
}
}
for(int i = 0; i < r; i++){
ptr = fgets(in, 10000, f);
char *p;
p = strtok(in, " \t");
while(p != NULL){
lim_row[i].push_back(RowLimit(atoi(p)));
p = strtok(NULL, " \t");
}
}
}
void readInput(){
char in[10000];//big enough to read a line of limit...
char* ptr;
if(fscanf(f, "%d %d", &r, &c) != 2){
return;
}
lim_row.clear(); lim_col.clear();
lim_row.resize(r); lim_col.resize(c);
ptr = fgets(in, 10000, f);//dumb
for(int i = 0; i < r; i++){
ptr = fgets(in, 10000, f);
char *p;
p = strtok(in, " ");
while(p != NULL){
lim_row[i].push_back(RowLimit(atoi(p)));
p = strtok(NULL, " ");
}
}
for(int i = 0; i < c; i++){
ptr = fgets(in, 10000, f);
char *p;
p = strtok(in, " ");
while(p != NULL){
lim_col[i].push_back(ColLimit(atoi(p)));
p = strtok(NULL, " ");
}
}
}
};