-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtc_generator.cpp
95 lines (76 loc) · 2.57 KB
/
tc_generator.cpp
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
92
93
94
95
// Aditya_Chandra
#include <bits/stdc++.h>
using namespace std;
void create_input_files(int total_testcases) {
for (int i = 0; i < total_testcases; i++) {
fstream file;
string filename = "input";
filename += (i < 10 ? "0" + to_string(i) : to_string(i)) + ".txt";
file.open("input/" + filename, ios::out);
if (!file) {
cout << "Error in creating input " << filename << endl;
} else {
cout << filename + " created successfully!" << endl;
}
file.close();
}
}
void create_output_files(int total_testcases) {
for (int i = 0; i < total_testcases; i++) {
fstream file;
string filename = "output";
filename += (i < 10 ? "0" + to_string(i) : to_string(i)) + ".txt";
file.open("output/" + filename, ios::out);
if (!file) {
cout << "Error in creating output " << filename << endl;
} else {
cout << filename + " created successfully!" << endl;
}
file.close();
}
}
void populate(int total_testcases) {
for (int f_i = 0; f_i < total_testcases; f_i++) {
cout << "input" << f_i << endl;
/*-------------------------------------------------------------*/
// Enter the input format for the problem;
int n;
cin >> n;
vector<int> v(n, 0);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
/*--------------------------------------------------------------*/
string input_filename = "input";
input_filename += (f_i < 10 ? "0" + to_string(f_i) : to_string(f_i)) + ".txt";
ofstream ipf("input/" + input_filename);
// Writing the input to a file
ipf << n << endl;
for (auto x : v) {
ipf << x << " ";
}
ipf << endl;
ipf.close();
string output_filename = "output";
output_filename += (f_i < 10 ? "0" + to_string(f_i) : to_string(f_i)) + ".txt";
ofstream opf("output/" + output_filename);
/*------------------------------------------------------------------*/
// Paste the Solution snippet for the problem
int sum = 0;
for(int i = 0; i < n; i++){
sum += v[i];
}
// Writing to output file
opf << sum << endl;
opf.close();
/*--------------------------------------------------------------------*/
}
}
int main() {
cout << "Enter the number of tests to be generated" << endl;
int n;
cin >> n;
create_input_files(n);
create_output_files(n);
populate(n);
}