Skip to content

Commit 965805a

Browse files
committed
updated boilderplate
1 parent 8d85fb1 commit 965805a

File tree

2 files changed

+43
-144
lines changed

2 files changed

+43
-144
lines changed

dist/test_cases/solution.cpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
1-
#include <iostream>
2-
#include <fstream>
3-
#include <sstream>
4-
#include <vector>
5-
#include <algorithm>
6-
#include <string>
1+
#include <bits/stdc++.h>
72
using namespace std;
83

9-
// Function to reverse words in a string
10-
string reverseWords(const string& s) {
4+
string reverseWords(const string &s) {
115
istringstream iss(s);
126
vector<string> words;
137
string word;
148

15-
// Split the input string into words
9+
// Split the string into words
1610
while (iss >> word) {
1711
words.push_back(word);
1812
}
1913

20-
// Reverse the list of words
14+
// Reverse the order of words
2115
reverse(words.begin(), words.end());
2216

23-
// Join the reversed list into a single string with a single space
24-
ostringstream oss;
25-
for (size_t i = 0; i < words.size(); ++i) {
26-
if (i != 0) {
27-
oss << " ";
28-
}
29-
oss << words[i];
17+
// Join the words back into a single string
18+
string reversed;
19+
for (const auto &w : words) {
20+
reversed += w + " ";
3021
}
3122

32-
return oss.str();
33-
}
23+
// Remove the trailing space
24+
if (!reversed.empty()) {
25+
reversed.pop_back();
26+
}
3427

28+
return reversed;
29+
}
3530
// Function to run the test case
36-
void runTestCase(int n, string (*func)(const string&)) {
31+
void runTestCase(int n) {
3732
string filePath = "../test_cases/input_" + to_string(n) + ".txt";
3833
ifstream file(filePath);
3934

@@ -42,17 +37,19 @@ void runTestCase(int n, string (*func)(const string&)) {
4237
return;
4338
}
4439

45-
string line;
46-
getline(file, line);
47-
file.close();
48-
49-
string result = func(line);
40+
// if your input files has vector/array uncomment the below code
41+
// Read the array from the file
42+
string ans;
43+
getline(file,ans);
44+
string result = reverseWords(ans);
45+
// Print the result
5046
cout << result << endl;
47+
file.close();
5148
}
5249

5350
int main() {
5451
// Example usage
55-
// Provide the test case number and function name
56-
runTestCase(1, reverseWords);
52+
runTestCase(1); // Adjust the number as needed for your actual test case
5753
return 0;
58-
}
54+
}
55+

src/extension.ts

Lines changed: 18 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -127,135 +127,37 @@ run_test_case()`
127127

128128

129129
: `#include <bits/stdc++.h>
130-
#include <filesystem>
131-
#include <functional>
132-
#include <iostream>
133-
#include <sstream>
134-
#include <string>
135-
#include <vector>
136-
137130
using namespace std;
138-
namespace fs = std::filesystem;
139-
140-
// Parse values from string
141-
template <typename T>
142-
T parseValue(const string& str) {
143-
istringstream iss(str);
144-
T value;
145-
iss >> value;
146-
return value;
147-
}
148131
149-
// Template specialization for string
150-
template <>
151-
string parseValue<string>(const string& str) {
152-
// Remove quotes if present
153-
if (str.size() >= 2 && str.front() == '"' && str.back() == '"') {
154-
return str.substr(1, str.size() - 2);
155-
}
156-
return str;
157-
}
132+
//write the code logic here
158133
159-
// Parse arrays from string
160-
template <typename T>
161-
vector<T> parseArray(const string& str) {
162-
vector<T> result;
163-
string trimmedStr = str.substr(1, str.size() - 2); // Remove brackets
164-
istringstream iss(trimmedStr);
165-
string item;
166-
while (getline(iss, item, ',')) {
167-
result.push_back(parseValue<T>(item));
168-
}
169-
return result;
170-
}
171134
172-
// Function to detect data type from string
173-
template <typename T>
174-
T detectAndParseValue(const string& str) {
175-
if (str.empty()) {
176-
throw runtime_error("Empty input string");
177-
}
178-
179-
// Check if it's an array
180-
if (str.front() == '[' && str.back() == ']') {
181-
return parseArray<typename T::value_type>(str);
182-
}
183-
184-
// Check if it's a string (quoted)
185-
if (str.front() == '"' && str.back() == '"') {
186-
return parseValue<T>(str);
187-
}
188-
189-
// Otherwise treat as numeric or other type
190-
return parseValue<T>(str);
191-
}
135+
// Function to run the tes\ case
136+
void runTestCase(int n) {
137+
string filePath = "../test_cases/input_" + to_string(n) + ".txt";
138+
ifstream file(filePath);
192139
193-
// Generic function to run test cases
194-
template <typename T>
195-
void run_test_case(int test_case_number, const function<void(const T&)>& solution_function) {
196-
fs::path base_directory = fs::path(__FILE__).parent_path().parent_path();
197-
fs::path file_path = base_directory / "test_cases" / ("input_" + to_string(test_case_number) + ".txt");
198-
199-
try {
200-
ifstream file(file_path);
201-
if (!file.is_open()) {
202-
throw runtime_error("File not found at " + file_path.string());
203-
}
204-
205-
string line;
206-
vector<string> lines;
207-
while (getline(file, line)) {
208-
lines.push_back(line);
209-
}
210-
211-
if (lines.empty()) {
212-
throw runtime_error("Invalid input format");
213-
}
214-
215-
// Parse input based on type T
216-
T parsed_input = detectAndParseValue<T>(lines[0]);
217-
solution_function(parsed_input);
218-
219-
} catch (const exception& e) {
220-
cerr << "Error: " << e.what() << endl;
140+
if (!file.is_open()) {
141+
cerr << "Error: File not found at " << filePath << ". Check the file path and try again." << endl;
142+
return;
221143
}
222-
}
223144
224-
// -------------------- SOLUTION TEMPLATE --------------------
225-
// MODIFY THIS SECTION FOR YOUR SPECIFIC PROBLEM
145+
// if your input files has vector/array uncomment the below code
146+
// Read the array from the file
226147
227-
void solution(const vector<string>& args) {
228-
// Example parsing different types of inputs
229-
// Modify according to your problem requirements
230-
231-
// For array input: [1,2,3]
232-
if (!args.empty() && args[0][0] == '[') {
233-
auto arr = parseArray<int>(args[0]);
234-
235-
}
236-
237-
// For string input: "hello"
238-
if (args.size() >= 2 && args[1][0] == '"') {
239-
string str = args[1].substr(1, args[1].length() - 2);
240-
}
241-
242-
// For integer input: 42
243-
if (args.size() >= 3) {
244-
int num = parseValue<int>(args[2]);
245-
}
246-
247-
// YOUR SOLUTION LOGIC GOES HERE
248-
148+
// Call the function and print the result(pass all the varbles that you have read from the file)
149+
//<data type> result = <function_name>(<variables>);
249150
151+
cout << result << endl;
250152
}
251153
252154
int main() {
253-
// Run single test case
254-
run_test_case<vector<int>>(1, solution);
255-
256-
155+
// Example usage
156+
runTestCase(); // Adjust the number as needed for your actual test case
257157
return 0;
258-
}`;
158+
}
159+
160+
`;
259161

260162

261163

0 commit comments

Comments
 (0)