Is there any way to put the Input automatically?

0

Shortly in a programming contest I came across the problem of having to put more than 250 Inputs into one problem. I would like to know if there is any way to put Inputs other than 1 by 1, by hand!

    
asked by anonymous 11.05.2015 / 16:23

3 answers

0

The most practical answer is yes. You can play the inputs you need inside a TXT file and read the program.

If you are using Linux to use an inbound redirection. A very rough example:

Suppose you receive the Inputs in the following format

N
o

Since 'N' is the total number of inputs and 'o' is the input of each value, eg

10
1
2
3
4
5
6
7
8
9
10

I saved this guy as a test.txt

Ex. of reading in C ++

#include <iostream>

int main() {
        int N = 0;

        std::cin >> N;

        for (int i = 0; i < N; i++) {
                int o;
                std::cin >> o;
                std::cout << o << std::endl;
        }
}

Compiling

g++ -o teste teste.c

Running on some * nix with input redirect and result

adirkuhn: ~ $ ./teste < teste.txt        
1
2
3
4
5
6
7
8
9
10
adirkuhn: ~ $ 

Example 2: test2.txt

5
31
32
33
34
35

Running and result:

adirkuhn: ~ $ ./teste < teste2.txt 
31
32
33
34
35
adirkuhn: ~ $ 
    
02.07.2015 / 15:39
0
  

I answered the question before the Question Author specifies all allowed languages, but this answer can be used as a subsidy (the idea is literally the same only changes the language) for the construction of the answer, for details on this conflict of languages see this discussion: meta .en.stackoverflow

If you can use a language (PHP in my example) you can go with% as much as you want on the page.

foreach($sites as $site){
    printSite($site);
}

function printSite($site){
    echo '
    <div class="checkbox">
         <label><input type="checkbox" name="site[]" value="'.$site.'">'.$site.'</label>
    </div>
    ';
 }
    
11.05.2015 / 16:33
0

The possibility of redirecting input is a matter of survival for development, testing. Even for the organization of computer tournaments ...

Taking the case mentioned "average of two hundred numbers" follows some examples of tests (unix + bash, adaptable to other environments)

0) if we have a known file

./myprogram < file

1) The average of 200 equal numbers must give this number

yes 33 | head -200 | ./myprogram 

You have to give 33;

2) the average numbers from 1 to 200

seq 200 | ./myprogram

You have to give 100.5

3) idem for this sequence after shuffling:

seq 200 | shuf | ./myprogram

4) eventually add the test to the makefile:

test: myprogram
    diff <(./myprogram < file) <(echo 53)                 && echo OK
    diff <(yes 33 | head -200| ./myprogram) <(echo 33)    && echo OK
    diff <(seq 200 | shuf    | ./myprogram) <(echo 100.5) && echo OK
    
01.09.2015 / 11:22