In a lot online judge problems, the format for the input is as follows: first line is the number of test cases. Let’s say X. Then X lines after that are the conditions for each test case.
In the example below, there are two test cases. Each test case specify the upper and lower bound for which primes should be shown in the output.
Input:
2
1 10
3 5
Output:
2
3
5
7
3
5
Now for my question. Right now, my program can handle one test case like so:
int main()
{
TestCase t;
t.setRange();
t.compute();
t.print();
}
How can I create X amount of TestCases without naming them all ‘t’?
X is specified at rumtime.
You can make a
std::vector<TestCase> allofem;andallofem.push_back(TestCase())Xtimes; remember to#include <vector>of course. Then you can loop onallofemand compute and then print on each item.