Skip to content

Commit

Permalink
allowing to not specify format string in repeat inout
Browse files Browse the repository at this point in the history
  • Loading branch information
Harniver committed Dec 9, 2023
1 parent 393778c commit a92f3a6
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# make-templates 0.2.002
# make-templates 0.2.003

This is a simple python-based tool generating solution templates (containing code for reading input and writing output), for tasks in either the yaml format for CMS or in the Terry format.

Expand Down
35 changes: 33 additions & 2 deletions make_templates/targets/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
templates['it']['rep'] = """
## Formato di input
La prima riga del file di input contiene un intero $%s$, il numero di casi di test. Seguono $%s$ casi di test, ognuno preceduto da una riga vuota.
Ogni caso di test è composto come segue:
%s
## Formato di output
Il file di output deve contenere $%s$ righe relative ai diversi casi di test, ciascuna composta da%s
"""

templates['it']['fmt'] = """
## Formato di input
La prima riga del file di input contiene un intero $%s$, il numero di casi di test. Seguono $%s$ casi di test, numerati da $1$ a $%s$. Ogni caso di test è preceduto da una riga vuota.
Ogni caso di test è composto come segue:
Expand All @@ -33,6 +47,20 @@
templates['en']['rep'] = """
## Input Format
The first line of the input file contains a single integer $%s$, the number of test cases. $%s$ test cases follow, each preceded by an empty line.
Each test case consists of:
%s
## Output Format
The output file must contain $%s$ lines corresponding to the test cases, each consisting of %s
"""

templates['en']['fmt'] = """
## Input Format
The first line of the input file contains a single integer $%s$, the number of test cases. $%s$ test cases follow, numbered from $1$ to $%s$, each preceded by an empty line.
Each test case consists of:
Expand Down Expand Up @@ -186,11 +214,14 @@ def build_block(prog:Block, lang:str):
def generate(name:str, prog:Block, lang:str, bounds:dict):
if isinstance(prog.code[-1], Repeat):
rep = prog.code[-1]
fmt = rep.code.code[-2].format[1:-1]
fmt = rep.code.code[-2].format[1:-1] if isinstance(rep.code.code[-2], FormatLine) else ""
T = rep.bound
out = rep.code.code[-1]
prog.code = rep.code.code[1:-2]
t = templates[lang]['rep'] % (T, T, T, "%s", fmt.replace("{}", rep.idx), rep.idx, "%s")
if fmt == "":
t = templates[lang]['rep'] % (T, T, "%s", rep.bound, "%s")
else:
t = templates[lang]['fmt'] % (T, T, T, "%s", fmt.replace("{}", rep.idx), rep.idx, "%s")
else:
out = prog.code[-1]
prog.code = prog.code[:-1]
Expand Down
37 changes: 35 additions & 2 deletions make_templates/targets/tex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
templates['it']['rep'] = """
\InputFile
La prima riga del file di input contiene un intero $%s$, il numero di casi di test. Seguono $%s$ casi di test, ognuno preceduto da una riga vuota.
Ogni caso di test è composto come segue:
\\begin{itemize}
%s\end{itemize}
\OutputFile
Il file di output deve contenere $%s$ righe relative ai diversi casi di test, ciascuna composta da%s
"""

templates['it']['fmt'] = """
\InputFile
La prima riga del file di input contiene un intero $%s$, il numero di casi di test. Seguono $%s$ casi di test, numerati da $1$ a $%s$. Ogni caso di test è preceduto da una riga vuota.
Ogni caso di test è composto come segue:
Expand Down Expand Up @@ -35,6 +50,21 @@
templates['en']['rep'] = """
\InputFile
The first line of the input file contains a single integer $%s$, the number of test cases. $%s$ test cases follow, each preceded by an empty line.
Each test case consists of:
\\begin{itemize}
%s\end{itemize}
\OutputFile
The output file must contain $%s$ lines corresponding to the test cases, each consisting of %s
"""

templates['en']['fmt'] = """
\InputFile
The first line of the input file contains a single integer $%s$, the number of test cases. $%s$ test cases follow, numbered from $1$ to $%s$, each preceded by an empty line.
Each test case consists of:
Expand Down Expand Up @@ -190,11 +220,14 @@ def build_block(prog:Block, lang:str):
def generate(name:str, prog:Block, lang:str, bounds:dict):
if isinstance(prog.code[-1], Repeat):
rep = prog.code[-1]
fmt = rep.code.code[-2].format[1:-1]
fmt = rep.code.code[-2].format[1:-1] if isinstance(rep.code.code[-2], FormatLine) else ""
T = rep.bound
out = rep.code.code[-1]
prog.code = rep.code.code[1:-2]
t = templates[lang]['rep'] % (T, T, T, "%s", fmt.replace("{}", rep.idx), rep.idx, "%s")
if fmt == "":
t = templates[lang]['rep'] % (T, T, "%s", rep.bound, "%s")
else:
t = templates[lang]['fmt'] % (T, T, T, "%s", fmt.replace("{}", rep.idx), rep.idx, "%s")
else:
out = prog.code[-1]
prog.code = prog.code[:-1]
Expand Down
9 changes: 9 additions & 0 deletions tests/repeated/att/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
4

hello

my

wonderful

world
4 changes: 4 additions & 0 deletions tests/repeated/att/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0
0
0
0
9 changes: 9 additions & 0 deletions tests/repeated/inout.slide
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repeat test upto T:

input:

string N;

output:

int ans;
Empty file added tests/repeated/limits.py
Empty file.
Empty file added tests/repeated/sol/soluzione.x
Empty file.
Empty file.
35 changes: 35 additions & 0 deletions tests/repeated/statement/english.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
\usepackage{xcolor}
\usepackage{caption}
\usepackage{afterpage}
\usepackage{pifont,mdframed}
\usepackage[bottom]{footmisc}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

This is the problem statement.

\begin{warning}
Among the attachments of this task you may find a template file \texttt{repeated.*} with a sample incomplete implementation.
\end{warning}


\InputFile

The first line of the input file contains the relevant data.


\OutputFile

The output file must contain the correct answer.


\Constraints

\begin{itemize}[nolistsep, itemsep=2mm]
\item No constraints.
\end{itemize}

\Scoring

Your program will not gain any score.
25 changes: 25 additions & 0 deletions tests/repeated/statement/statement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
> **Attenzione**: Questo task ha un tempo limite di 10 minuti per l'invio della soluzione. Una volta richiesto un input, il timer partirà in automatico, e dopo la scadenza non sarà più possibile inviare una soluzione per quell'input.
> *È sempre possibile richiedere un nuovo input*, per cui non preoccuparti se il timer scade: dovrai semplicemente richiedere e scaricare un nuovo input.
> _Per aiutarti con questo task, abbiamo preparato delle **tracce di soluzione**, che includono solo le parti di lettura dell'input e scrittura dell'output (da tastiera e su schermo). Puoi decidere se leggere/scrivere su file decommentando le opportune righe di codice._
>
> - _Scarica la traccia in C: [repeated.c](repeated.c)_
## Descrizione del problema

Questo è un problema.


## Formato di input

Il file di input è misterioso.


## Formato di output

Il file di output deve contenere la risposta corretta.


## Esempi di input/output

Gli esempi descritti sopra non si rappresentano nel formato di input/output.
1 change: 1 addition & 0 deletions tests/repeated/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: repeated

0 comments on commit a92f3a6

Please sign in to comment.