Hello,
I’m making an IN/OUT puzzle and I have this problem with the stub generator, that is - I don’t know how to do it since it’s a little complicated and all I tried has failed.
In this puzzle, the program should read the number of different polygons, then it should read the number of vertices of each polygon (in a loop; would be usually different) and then it should read the polygons’ vertices (in another loop or multiple loops). Alternatively, it could read the vertices right after reading the number of them for each polygon or they could be written in one line.
So these are some of the ways the input could look like:
Input version 1
2
3
3
X11 Y11
X12 Y12
X13 Y13
X21 Y21
X22 Y22
X23 Y23
Input version 2
2
3
X11 Y11
X12 Y12
X13 Y13
3
X21 Y21
X22 Y22
X23 Y23
And this would be the code that I’d like the stub generator to generate (examples in C and Python):
Version 1
C
int n;
scanf("%d", &n);
int m[n];
for (int i = 0; i < n; i++) {
scanf("%d", &m[i]);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m[i]; j++) {
float x;
float y;
scanf("%f%f", &x, &y);
}
}
Python
n = int(input())
m = []
for i in range(n):
m.append(int(input()))
for i in range(n):
for j in range(m[i])
x, y = [float(j) for j in input().split()]
Version 2
C
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int m;
scanf("%d", &m);
for (int j = 0; j < m; j++) {
float x;
float y;
scanf("%f%f", &x, &y);
}
}
Python
n = int(input())
for i in range(n):
m = int(input())
for j in range(m)
x, y = [float(j) for j in input().split()]
The closest I got was this stub:
read n:int
loop n read m:int
loop m read x:float y:float
which obviously doesn’t work. ![]()
I don’t know if there is a way to do arrays or put multiple commands in one loop but I sure didn’t see a documented one. I wouldn’t care much about this but since this is an IN/OUT puzzle, it doesn’t let me try out my code or publish it unless the stub matches the input data. Do you know of a possible approach?
Thank you!