Skip to content

Commit 1941b47

Browse files
committed
fixed
1 parent 965805a commit 1941b47

File tree

6 files changed

+43
-146
lines changed

6 files changed

+43
-146
lines changed

build/CMakeCache.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ CMAKE_COLOR_MAKEFILE:BOOL=ON
2929
//No help, variable specified on the command line.
3030
CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++
3131

32-
//C compiler
33-
CMAKE_C_COMPILER:STRING=/usr/bin/gcc
32+
//No help, variable specified on the command line.
33+
CMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc
3434

3535
//A wrapper around 'ar' adding the appropriate '--plugin' option
3636
// for the GCC compiler

dist/extension.js

Lines changed: 24 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -297703,12 +297703,12 @@ var CommandTreeDataProvider = class {
297703297703
this.onDidChangeTreeData = this._onDidChangeTreeData.event;
297704297704
// Mapping of command IDs to their display names, icons, and colors
297705297705
this.extensionCommands = {
297706-
"leetcode-cph-helper-by-ashish.fetchLeetCodeTestCases": { label: "Fetch Test Cases", icon: "cloud-download", color: "charts.green" },
297707-
"leetcode-cph-helper-by-ashish.runTestCases": { label: "Run Test Cases", icon: "play-circle", color: "charts.blue" },
297708-
"leetcode-cph-helper-by-ashish.writeSolutionFile": { label: "Write Solution File", icon: "file-code", color: "charts.yellow" },
297709-
"leetcode-test-case-manager.getSolutionFileDirectory": { label: "Get Solution File Directory", icon: "folder", color: "charts.orange" },
297710-
"leetcode-cph-helper-by-ashish.getIOFileDirectory": { label: "Get I/O File Directory", icon: "folder", color: "charts.red" },
297711-
"leetcode-cph-helper-by-ashish.showLeetCodeProblemLinks": { label: "Show LeetCode Problem Links", icon: "link", color: "charts.purple" }
297706+
"leetcode-cph-helper-by-ashish.fetchLeetCodeTestCases": { label: "Fetch Test Cases(CTRL+1)", icon: "cloud-download", color: "charts.green" },
297707+
"leetcode-cph-helper-by-ashish.runTestCases": { label: "Run Test Cases(CTRL+5)", icon: "play-circle", color: "charts.blue" },
297708+
"leetcode-cph-helper-by-ashish.writeSolutionFile": { label: "Write Solution File(CTRL+4)", icon: "file-code", color: "charts.yellow" },
297709+
"leetcode-test-case-manager.getSolutionFileDirectory": { label: "Get Solution File Directory(CTRL+3)", icon: "folder", color: "charts.orange" },
297710+
"leetcode-cph-helper-by-ashish.getIOFileDirectory": { label: "Get I/O File Directory(CTRL+2)", icon: "folder", color: "charts.red" },
297711+
"leetcode-cph-helper-by-ashish.showLeetCodeProblemLinks": { label: "Show LeetCode Problem Links(CTRL+6)", icon: "link", color: "charts.purple" }
297712297712
};
297713297713
}
297714297714
// Returns a TreeItem representation of the given element
@@ -297851,135 +297851,37 @@ function activate(context2) {
297851297851
# Provide the test case number and function name
297852297852
#run_test_case(TEST_CASE_NUMBER, FUNCTION_NAME);
297853297853
run_test_case()` : `#include <bits/stdc++.h>
297854-
#include <filesystem>
297855-
#include <functional>
297856-
#include <iostream>
297857-
#include <sstream>
297858-
#include <string>
297859-
#include <vector>
297860-
297861297854
using namespace std;
297862-
namespace fs = std::filesystem;
297863297855

297864-
// Parse values from string
297865-
template <typename T>
297866-
T parseValue(const string& str) {
297867-
istringstream iss(str);
297868-
T value;
297869-
iss >> value;
297870-
return value;
297871-
}
297856+
//write the code logic here
297872297857

297873-
// Template specialization for string
297874-
template <>
297875-
string parseValue<string>(const string& str) {
297876-
// Remove quotes if present
297877-
if (str.size() >= 2 && str.front() == '"' && str.back() == '"') {
297878-
return str.substr(1, str.size() - 2);
297879-
}
297880-
return str;
297881-
}
297882297858

297883-
// Parse arrays from string
297884-
template <typename T>
297885-
vector<T> parseArray(const string& str) {
297886-
vector<T> result;
297887-
string trimmedStr = str.substr(1, str.size() - 2); // Remove brackets
297888-
istringstream iss(trimmedStr);
297889-
string item;
297890-
while (getline(iss, item, ',')) {
297891-
result.push_back(parseValue<T>(item));
297892-
}
297893-
return result;
297894-
}
297895-
297896-
// Function to detect data type from string
297897-
template <typename T>
297898-
T detectAndParseValue(const string& str) {
297899-
if (str.empty()) {
297900-
throw runtime_error("Empty input string");
297901-
}
297902-
297903-
// Check if it's an array
297904-
if (str.front() == '[' && str.back() == ']') {
297905-
return parseArray<typename T::value_type>(str);
297906-
}
297907-
297908-
// Check if it's a string (quoted)
297909-
if (str.front() == '"' && str.back() == '"') {
297910-
return parseValue<T>(str);
297911-
}
297912-
297913-
// Otherwise treat as numeric or other type
297914-
return parseValue<T>(str);
297915-
}
297916-
297917-
// Generic function to run test cases
297918-
template <typename T>
297919-
void run_test_case(int test_case_number, const function<void(const T&)>& solution_function) {
297920-
fs::path base_directory = fs::path(__FILE__).parent_path().parent_path();
297921-
fs::path file_path = base_directory / "test_cases" / ("input_" + to_string(test_case_number) + ".txt");
297922-
297923-
try {
297924-
ifstream file(file_path);
297925-
if (!file.is_open()) {
297926-
throw runtime_error("File not found at " + file_path.string());
297927-
}
297859+
// Function to run the tes case
297860+
void runTestCase(int n) {
297861+
string filePath = "../test_cases/input_" + to_string(n) + ".txt";
297862+
ifstream file(filePath);
297928297863

297929-
string line;
297930-
vector<string> lines;
297931-
while (getline(file, line)) {
297932-
lines.push_back(line);
297933-
}
297934-
297935-
if (lines.empty()) {
297936-
throw runtime_error("Invalid input format");
297937-
}
297938-
297939-
// Parse input based on type T
297940-
T parsed_input = detectAndParseValue<T>(lines[0]);
297941-
solution_function(parsed_input);
297942-
297943-
} catch (const exception& e) {
297944-
cerr << "Error: " << e.what() << endl;
297864+
if (!file.is_open()) {
297865+
cerr << "Error: File not found at " << filePath << ". Check the file path and try again." << endl;
297866+
return;
297945297867
}
297946-
}
297947297868

297948-
// -------------------- SOLUTION TEMPLATE --------------------
297949-
// MODIFY THIS SECTION FOR YOUR SPECIFIC PROBLEM
297869+
// if your input files has vector/array uncomment the below code
297870+
// Read the array from the file
297950297871

297951-
void solution(const vector<string>& args) {
297952-
// Example parsing different types of inputs
297953-
// Modify according to your problem requirements
297954-
297955-
// For array input: [1,2,3]
297956-
if (!args.empty() && args[0][0] == '[') {
297957-
auto arr = parseArray<int>(args[0]);
297958-
297959-
}
297960-
297961-
// For string input: "hello"
297962-
if (args.size() >= 2 && args[1][0] == '"') {
297963-
string str = args[1].substr(1, args[1].length() - 2);
297964-
}
297965-
297966-
// For integer input: 42
297967-
if (args.size() >= 3) {
297968-
int num = parseValue<int>(args[2]);
297969-
}
297970-
297971-
// YOUR SOLUTION LOGIC GOES HERE
297972-
297872+
// Call the function and print the result(pass all the varbles that you have read from the file)
297873+
//<data type> result = <function_name>(<variables>);
297973297874

297875+
cout << result << endl;
297974297876
}
297975297877

297976297878
int main() {
297977-
// Run single test case
297978-
run_test_case<vector<int>>(1, solution);
297979-
297980-
297879+
// Example usage
297880+
runTestCase(); // Adjust the number as needed for your actual test case
297981297881
return 0;
297982-
}`;
297882+
}
297883+
297884+
`;
297983297885
fs8.writeFileSync(filePath, boilerplate, "utf-8");
297984297886
const document2 = await vscode3.workspace.openTextDocument(filePath);
297985297887
await vscode3.window.showTextDocument(document2);

dist/extension.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/test_cases/solution

-97.8 KB
Binary file not shown.

src/solution

145 KB
Binary file not shown.

src/solution.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <algorithm>
77
#include <filesystem>
88

9-
namespace fs = std::experimental::filesystem;
9+
namespace fs = std::filesystem;
1010

1111
// Function to reverse words in a string
1212
std::string reverse_words(const std::string& s) {
@@ -27,33 +27,28 @@ std::string reverse_words(const std::string& s) {
2727
return oss.str();
2828
}
2929

30-
// Function to run a test case
31-
template <typename F>
32-
void run_test_case(int n, F solution_function) {
33-
fs::path base_dir = fs::path(__FILE__).parent_path().parent_path();
34-
fs::path input_path = base_dir / "test_cases" / ("input_" + std::to_string(n) + ".txt");
30+
// Function to run the test case
31+
void runTestCase(int n) {
32+
std::string filePath = "../test_cases/input_" + std::to_string(n) + ".txt";
33+
std::ifstream file(filePath);
3534

36-
if (!fs::exists(input_path)) {
37-
std::cerr << "Error: File not found at " << input_path << ". Check the file path and try again." << std::endl;
35+
if (!file.is_open()) {
36+
std::cerr << "Error: File not found at " << filePath << ". Check the file path and try again." << std::endl;
3837
return;
3938
}
4039

41-
try {
42-
std::ifstream input_file(input_path);
43-
if (!input_file.is_open()) {
44-
throw std::runtime_error("Could not open input file.");
45-
}
46-
std::string line;
47-
std::getline(input_file, line);
48-
49-
solution_function(line);
50-
51-
} catch (const std::exception& e) {
52-
std::cerr << "Error during test case execution: " << e.what() << std::endl;
40+
std::string line;
41+
if (std::getline(file, line)) {
42+
std::string result = reverse_words(line);
43+
std::cout << result << std::endl;
5344
}
45+
46+
file.close();
5447
}
5548

5649
int main() {
57-
run_test_case(2, reverse_words);
50+
// Example usage
51+
// Provide the test case number
52+
runTestCase(1); // Adjust the number as needed for your actual test case
5853
return 0;
5954
}

0 commit comments

Comments
 (0)