Skip to content

Commit 5370f63

Browse files
committed
updated logic for c++ code
1 parent c3ba0d9 commit 5370f63

File tree

7 files changed

+101
-88
lines changed

7 files changed

+101
-88
lines changed

dist/extension.js

Lines changed: 67 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13471,10 +13471,10 @@ var require_BrowserProcessor = __commonJS({
1347113471
const clientWindows = await Promise.all(topLevelTargetIds.map(async (targetId) => await this.#getWindowInfo(targetId)));
1347213472
const uniqueClientWindowIds = /* @__PURE__ */ new Set();
1347313473
const uniqueClientWindows = new Array();
13474-
for (const window4 of clientWindows) {
13475-
if (!uniqueClientWindowIds.has(window4.clientWindow)) {
13476-
uniqueClientWindowIds.add(window4.clientWindow);
13477-
uniqueClientWindows.push(window4);
13474+
for (const window5 of clientWindows) {
13475+
if (!uniqueClientWindowIds.has(window5.clientWindow)) {
13476+
uniqueClientWindowIds.add(window5.clientWindow);
13477+
uniqueClientWindows.push(window5);
1347813478
}
1347913479
}
1348013480
return { clientWindows: uniqueClientWindows };
@@ -281542,7 +281542,7 @@ __export(extension_exports, {
281542281542
deactivate: () => deactivate
281543281543
});
281544281544
module.exports = __toCommonJS(extension_exports);
281545-
var vscode3 = __toESM(require("vscode"));
281545+
var vscode4 = __toESM(require("vscode"));
281546281546
var fs8 = __toESM(require("fs"));
281547281547
var path12 = __toESM(require("path"));
281548281548

@@ -297554,6 +297554,7 @@ var import_child_process3 = require("child_process");
297554297554
var path11 = __toESM(require("path"));
297555297555
var fs7 = __toESM(require("fs"));
297556297556
var readline2 = __toESM(require("readline"));
297557+
var vscode2 = __toESM(require("vscode"));
297557297558
function normalizeOutput(output) {
297558297559
return output.replace(/\s+/g, "").trim();
297559297560
}
@@ -297684,9 +297685,13 @@ Running Test Case ${testCaseIndex}...`);
297684297685
`;
297685297686
console.log(`${resultMessage}Expected Output: ${expectedOutput}
297686297687
Actual Output: ${result.trim()}`);
297688+
vscode2.window.showInformationMessage(`${resultMessage}Expected Output: ${expectedOutput}
297689+
Actual Output: ${result.trim()}`, { modal: true });
297687297690
} else {
297688297691
console.log(`Output for Test Case ${testCaseIndex}:
297689297692
${result.trim()}`);
297693+
vscode2.window.showInformationMessage(`Output for Test Case ${testCaseIndex}:
297694+
${result.trim()}`, { modal: true });
297690297695
}
297691297696
} catch (error) {
297692297697
console.error(error);
@@ -297696,10 +297701,10 @@ ${result.trim()}`);
297696297701
main().catch((error) => console.error(error));
297697297702

297698297703
// src/commandTreeDataProvider.ts
297699-
var vscode2 = __toESM(require("vscode"));
297704+
var vscode3 = __toESM(require("vscode"));
297700297705
var CommandTreeDataProvider = class {
297701297706
constructor() {
297702-
this._onDidChangeTreeData = new vscode2.EventEmitter();
297707+
this._onDidChangeTreeData = new vscode3.EventEmitter();
297703297708
this.onDidChangeTreeData = this._onDidChangeTreeData.event;
297704297709
// Mapping of command IDs to their display names, icons, and colors
297705297710
this.extensionCommands = {
@@ -297720,7 +297725,7 @@ var CommandTreeDataProvider = class {
297720297725
if (element) {
297721297726
return Promise.resolve([]);
297722297727
} else {
297723-
const commands3 = vscode2.commands.getCommands(true);
297728+
const commands3 = vscode3.commands.getCommands(true);
297724297729
return commands3.then(
297725297730
(cmds) => cmds.filter((cmd) => Object.keys(this.extensionCommands).includes(cmd)).map((cmd) => {
297726297731
const commandInfo = this.extensionCommands[cmd];
@@ -297735,20 +297740,20 @@ var CommandTreeDataProvider = class {
297735297740
this._onDidChangeTreeData.fire();
297736297741
}
297737297742
};
297738-
var CommandTreeItem = class extends vscode2.TreeItem {
297743+
var CommandTreeItem = class extends vscode3.TreeItem {
297739297744
constructor(commandId, label, icon, color) {
297740-
super(label, vscode2.TreeItemCollapsibleState.None);
297745+
super(label, vscode3.TreeItemCollapsibleState.None);
297741297746
this.commandId = commandId;
297742297747
this.label = label;
297743297748
this.icon = icon;
297744297749
this.color = color;
297745297750
this.tooltip = this.label;
297746-
this.iconPath = new vscode2.ThemeIcon(this.icon);
297751+
this.iconPath = new vscode3.ThemeIcon(this.icon);
297747297752
this.command = {
297748297753
command: commandId,
297749297754
title: ""
297750297755
};
297751-
this.resourceUri = vscode2.Uri.parse(`color:${this.color}`);
297756+
this.resourceUri = vscode3.Uri.parse(`color:${this.color}`);
297752297757
}
297753297758
};
297754297759

@@ -297759,19 +297764,19 @@ function activate(context2) {
297759297764
if (!fs8.existsSync(baseDirectory)) {
297760297765
fs8.mkdirSync(baseDirectory, { recursive: true });
297761297766
}
297762-
const fetchCommand = vscode3.commands.registerCommand(
297767+
const fetchCommand = vscode4.commands.registerCommand(
297763297768
"leetcode-cph-helper-by-ashish.fetchLeetCodeTestCases",
297764297769
async () => {
297765-
const url = await vscode3.window.showInputBox({
297770+
const url = await vscode4.window.showInputBox({
297766297771
prompt: "Enter the LeetCode problem URL",
297767297772
placeHolder: "https://leetcode.com/problems/example-problem/description"
297768297773
});
297769297774
if (!url) {
297770-
vscode3.window.showWarningMessage("No URL provided!");
297775+
vscode4.window.showWarningMessage("No URL provided!");
297771297776
return;
297772297777
}
297773-
vscode3.window.withProgress(
297774-
{ location: vscode3.ProgressLocation.Notification, title: "Fetching LeetCode Test Cases..." },
297778+
vscode4.window.withProgress(
297779+
{ location: vscode4.ProgressLocation.Notification, title: "Fetching LeetCode Test Cases..." },
297775297780
async () => {
297776297781
try {
297777297782
const files = fs8.readdirSync(baseDirectory);
@@ -297781,52 +297786,52 @@ function activate(context2) {
297781297786
}
297782297787
});
297783297788
await fetchTestCases(url);
297784-
vscode3.window.showInformationMessage("Test cases fetched successfully!");
297789+
vscode4.window.showInformationMessage("Test cases fetched successfully!");
297785297790
} catch (error) {
297786-
vscode3.window.showErrorMessage(`Failed to fetch test cases: ${error}`);
297791+
vscode4.window.showErrorMessage(`Failed to fetch test cases: ${error}`);
297787297792
}
297788297793
}
297789297794
);
297790297795
}
297791297796
);
297792-
const getIOFileDirectoryCommand = vscode3.commands.registerCommand(
297797+
const getIOFileDirectoryCommand = vscode4.commands.registerCommand(
297793297798
"leetcode-cph-helper-by-ashish.getIOFileDirectory",
297794297799
async () => {
297795297800
try {
297796-
await vscode3.env.clipboard.writeText(baseDirectory);
297797-
vscode3.window.showInformationMessage(`I/O text file directory path copied to clipboard: ${baseDirectory}`);
297801+
await vscode4.env.clipboard.writeText(baseDirectory);
297802+
vscode4.window.showInformationMessage(`I/O text file directory path copied to clipboard: ${baseDirectory}`);
297798297803
} catch (error) {
297799-
vscode3.window.showErrorMessage(`Error: ${error}`);
297804+
vscode4.window.showErrorMessage(`Error: ${error}`);
297800297805
}
297801297806
}
297802297807
);
297803-
const getSolutionFileDirectoryCommand = vscode3.commands.registerCommand(
297808+
const getSolutionFileDirectoryCommand = vscode4.commands.registerCommand(
297804297809
"leetcode-test-case-manager.getSolutionFileDirectory",
297805297810
async () => {
297806297811
try {
297807297812
const solutionDir = path12.join(baseDirectory, "dist", "test_cases");
297808-
await vscode3.env.clipboard.writeText(solutionDir);
297809-
vscode3.window.showInformationMessage(`Solution directory path copied to clipboard: ${solutionDir}`);
297813+
await vscode4.env.clipboard.writeText(solutionDir);
297814+
vscode4.window.showInformationMessage(`Solution directory path copied to clipboard: ${solutionDir}`);
297810297815
} catch (error) {
297811-
vscode3.window.showErrorMessage(`Error copying solution directory path: ${error}`);
297816+
vscode4.window.showErrorMessage(`Error copying solution directory path: ${error}`);
297812297817
}
297813297818
}
297814297819
);
297815-
const writeSolutionFileCommand = vscode3.commands.registerCommand(
297820+
const writeSolutionFileCommand = vscode4.commands.registerCommand(
297816297821
"leetcode-cph-helper-by-ashish.writeSolutionFile",
297817297822
async () => {
297818297823
try {
297819-
const language = await vscode3.window.showQuickPick(["python", "cpp"], {
297824+
const language = await vscode4.window.showQuickPick(["python", "cpp"], {
297820297825
placeHolder: "Choose the programming language (python or cpp)"
297821297826
});
297822297827
if (!language) {
297823-
vscode3.window.showWarningMessage("No language selected!");
297828+
vscode4.window.showWarningMessage("No language selected!");
297824297829
return;
297825297830
}
297826297831
const baseFileName = language === "python" ? "solution.py" : "solution.cpp";
297827297832
let filePath = path12.join(baseDirectory, baseFileName);
297828297833
if (fs8.existsSync(filePath)) {
297829-
const action = await vscode3.window.showQuickPick(["Overwrite", "Create New File"], {
297834+
const action = await vscode4.window.showQuickPick(["Overwrite", "Create New File"], {
297830297835
placeHolder: `File '${baseFileName}' already exists. What would you like to do?`
297831297836
});
297832297837
if (action === "Create New File") {
@@ -297836,9 +297841,9 @@ function activate(context2) {
297836297841
filePath = path12.join(baseDirectory, newFileName);
297837297842
counter++;
297838297843
}
297839-
vscode3.window.showInformationMessage(`Creating new file: ${path12.basename(filePath)}`);
297844+
vscode4.window.showInformationMessage(`Creating new file: ${path12.basename(filePath)}`);
297840297845
} else if (action === "Overwrite") {
297841-
vscode3.window.showInformationMessage(`Overwriting existing file: ${baseFileName}`);
297846+
vscode4.window.showInformationMessage(`Overwriting existing file: ${baseFileName}`);
297842297847
} else {
297843297848
throw new Error("File creation cancelled.");
297844297849
}
@@ -297883,54 +297888,54 @@ int main() {
297883297888

297884297889
`;
297885297890
fs8.writeFileSync(filePath, boilerplate, "utf-8");
297886-
const document2 = await vscode3.workspace.openTextDocument(filePath);
297887-
await vscode3.window.showTextDocument(document2);
297888-
vscode3.window.showInformationMessage(`Solution file '${path12.basename(filePath)}' is ready in ${baseDirectory}.`);
297891+
const document2 = await vscode4.workspace.openTextDocument(filePath);
297892+
await vscode4.window.showTextDocument(document2);
297893+
vscode4.window.showInformationMessage(`Solution file '${path12.basename(filePath)}' is ready in ${baseDirectory}.`);
297889297894
} catch (error) {
297890-
vscode3.window.showErrorMessage(`Error: ${error}`);
297895+
vscode4.window.showErrorMessage(`Error: ${error}`);
297891297896
}
297892297897
}
297893297898
);
297894-
const runCommand = vscode3.commands.registerCommand(
297899+
const runCommand = vscode4.commands.registerCommand(
297895297900
"leetcode-cph-helper-by-ashish.runTestCases",
297896297901
async () => {
297897297902
try {
297898-
const activeEditor = vscode3.window.activeTextEditor;
297903+
const activeEditor = vscode4.window.activeTextEditor;
297899297904
if (!activeEditor) {
297900-
vscode3.window.showWarningMessage("No active editor detected. Please open your solution file first.");
297905+
vscode4.window.showWarningMessage("No active editor detected. Please open your solution file first.");
297901297906
return;
297902297907
}
297903297908
const filePath = activeEditor.document.fileName;
297904297909
const language = filePath.endsWith(".py") ? "python" : filePath.endsWith(".cpp") ? "cpp" : null;
297905297910
if (!language) {
297906-
vscode3.window.showWarningMessage("Unsupported file type. Only Python and C++ files are supported.");
297911+
vscode4.window.showWarningMessage("Unsupported file type. Only Python and C++ files are supported.");
297907297912
return;
297908297913
}
297909297914
if (!fs8.existsSync(baseDirectory)) {
297910-
vscode3.window.showErrorMessage("Test cases directory not found.");
297915+
vscode4.window.showErrorMessage("Test cases directory not found.");
297911297916
return;
297912297917
}
297913297918
const inputFiles = fs8.readdirSync(baseDirectory).filter((file) => file.startsWith("input_") && file.endsWith(".txt"));
297914297919
const totalTestCases = inputFiles.length;
297915297920
if (totalTestCases === 0) {
297916-
vscode3.window.showWarningMessage("No test cases found to run.");
297921+
vscode4.window.showWarningMessage("No test cases found to run.");
297917297922
return;
297918297923
}
297919297924
const testCaseOptions = inputFiles.map((file, index) => ({
297920297925
label: `Test Case ${index + 1}`,
297921297926
description: file,
297922297927
index: index + 1
297923297928
}));
297924-
const selectedTestCase = await vscode3.window.showQuickPick(testCaseOptions, {
297929+
const selectedTestCase = await vscode4.window.showQuickPick(testCaseOptions, {
297925297930
placeHolder: "Select a test case to run"
297926297931
});
297927297932
if (!selectedTestCase) {
297928-
vscode3.window.showWarningMessage("No test case selected!");
297933+
vscode4.window.showWarningMessage("No test case selected!");
297929297934
return;
297930297935
}
297931297936
const testCaseNumber = selectedTestCase.index;
297932-
vscode3.window.withProgress(
297933-
{ location: vscode3.ProgressLocation.Notification, title: "Running Test Case..." },
297937+
vscode4.window.withProgress(
297938+
{ location: vscode4.ProgressLocation.Notification, title: "Running Test Case..." },
297934297939
async () => {
297935297940
try {
297936297941
const results = [];
@@ -297949,39 +297954,43 @@ int main() {
297949297954
` : `Output for Test Case ${testCaseNumber}: ${normalizedResult}`;
297950297955
results.push(expectedOutput ? `${resultMessage}Expected Output: ${normalizedExpectedOutput}
297951297956
Actual Output: ${normalizedResult}` : resultMessage);
297957+
console.log(results.join("\n\n"));
297958+
vscode4.window.showInformationMessage(`Test Case Summary:
297959+
297960+
${results.join("\n\n")}`, { modal: true });
297952297961
} catch (innerError) {
297953297962
const errorMessage = innerError instanceof Error ? innerError.message : String(innerError);
297954297963
const actualOutput = "N/A";
297955297964
results.push(`\u274C\u{1F62D} Test Case ${testCaseNumber}: Failed! \u{1F62D}
297956297965
Error: ${errorMessage}
297957297966
Actual Output: ${actualOutput}`);
297958-
}
297959-
const summary = results.join("\n\n");
297960-
vscode3.window.showInformationMessage(`Test Case Summary:
297967+
console.log(results.join("\n\n"));
297968+
vscode4.window.showInformationMessage(`Test Case Summary:
297961297969

297962-
${summary}`, { modal: true });
297970+
${results.join("\n\n")}`, { modal: true });
297971+
}
297963297972
} catch (error) {
297964-
vscode3.window.showErrorMessage(`Error running test case: ${String(error)}`);
297973+
vscode4.window.showErrorMessage(`Error running test case: ${String(error)}`);
297965297974
}
297966297975
}
297967297976
);
297968297977
} catch (error) {
297969-
vscode3.window.showErrorMessage(`Error: ${error}`);
297978+
vscode4.window.showErrorMessage(`Error: ${error}`);
297970297979
}
297971297980
}
297972297981
);
297973-
const showLeetCodeProblemLinksCommand = vscode3.commands.registerCommand(
297982+
const showLeetCodeProblemLinksCommand = vscode4.commands.registerCommand(
297974297983
"leetcode-cph-helper-by-ashish.showLeetCodeProblemLinks",
297975297984
async () => {
297976297985
const problemLinksFilePath = path12.join(context2.extensionPath, "leetcode_problems_link.txt");
297977-
const document2 = await vscode3.workspace.openTextDocument(problemLinksFilePath);
297978-
await vscode3.window.showTextDocument(document2);
297986+
const document2 = await vscode4.workspace.openTextDocument(problemLinksFilePath);
297987+
await vscode4.window.showTextDocument(document2);
297979297988
}
297980297989
);
297981297990
context2.subscriptions.push(fetchCommand, showLeetCodeProblemLinksCommand, getIOFileDirectoryCommand, getSolutionFileDirectoryCommand, writeSolutionFileCommand, runCommand);
297982297991
const commandTreeDataProvider = new CommandTreeDataProvider();
297983-
vscode3.window.registerTreeDataProvider("leetcodeHelperCommands", commandTreeDataProvider);
297984-
vscode3.commands.executeCommand("workbench.view.extension.leetcodeHelper");
297992+
vscode4.window.registerTreeDataProvider("leetcodeHelperCommands", commandTreeDataProvider);
297993+
vscode4.commands.executeCommand("workbench.view.extension.leetcodeHelper");
297985297994
}
297986297995
function deactivate() {
297987297996
console.log("LeetCode Helper Extension Deactivated!");

dist/extension.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/test_cases/solution

1008 Bytes
Binary file not shown.

dist/test_cases/solution.cpp

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

4-
string reverseWords(const string &s) {
10+
string reverseWords(string s) {
11+
// Remove extra quotes from the input string
12+
s.erase(remove(s.begin(), s.end(), '"'), s.end());
13+
514
istringstream iss(s);
615
vector<string> words;
716
string word;
8-
9-
// Split the string into words
1017
while (iss >> word) {
1118
words.push_back(word);
1219
}
13-
14-
// Reverse the order of words
1520
reverse(words.begin(), words.end());
16-
17-
// Join the words back into a single string
18-
string reversed;
19-
for (const auto &w : words) {
20-
reversed += w + " ";
21+
string result;
22+
for (size_t i = 0; i < words.size(); ++i) {
23+
result += words[i];
24+
if (i < words.size() - 1) {
25+
result += " ";
26+
}
2127
}
22-
23-
// Remove the trailing space
24-
if (!reversed.empty()) {
25-
reversed.pop_back();
26-
}
27-
28-
return reversed;
28+
return result;
2929
}
30+
3031
// Function to run the test case
3132
void runTestCase(int n) {
3233
string filePath = "../test_cases/input_" + to_string(n) + ".txt";
@@ -37,19 +38,18 @@ void runTestCase(int n) {
3738
return;
3839
}
3940

40-
// if your input files has vector/array uncomment the below code
4141
// Read the array from the file
42-
string ans;
43-
getline(file,ans);
44-
string result = reverseWords(ans);
42+
string ans;
43+
getline(file, ans);
44+
string result = reverseWords(ans);
4545
// Print the result
4646
cout << result << endl;
4747
file.close();
4848
}
4949

5050
int main() {
5151
// Example usage
52-
runTestCase(1); // Adjust the number as needed for your actual test case
52+
runTestCase(3); // Adjust the number as needed for your actual test case
5353
return 0;
5454
}
5555

0 commit comments

Comments
 (0)