Skip to content

Commit 920ecb6

Browse files
author
Carlos Leonard
committed
update
1 parent 49d660a commit 920ecb6

12 files changed

+63
-9
lines changed

77_PalindromeSwapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ int main()
6060
cout << PalindromeSwapper("anna") << endl; // anna
6161
cout << PalindromeSwapper("kyaak") << endl; // kayak
6262
cout << PalindromeSwapper("rcaecar") << endl; // racecar
63-
cout << PalindromeSwapper("madam") << endl;
63+
cout << PalindromeSwapper("madam") << endl; // madam
6464
return 0;
6565
}

78_RemoveBrackets.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// For this challenge you will determine how to create evenly matched brackets.
2+
/*
3+
have the function RemoveBrackets(str) take the str string parameter being passed, which will contain only the characters "(" and ")", and determine the minimum number of brackets that need to be removed to create a string of correctly matched brackets. For example: if str is "(()))" then your program should return the number 1. The answer could potentially be 0, and there will always be at least one set of matching brackets in the string.
4+
*/
5+
6+
#include <iostream>
7+
#include <string>
8+
#include <stack>
9+
using namespace std;
10+
11+
/*
12+
traverse the string
13+
any opening tags get stored in stack
14+
if we have a closing tag compare it to the stack
15+
If they match than pop the top value of our stack
16+
if they do not match we will still add it to the stack
17+
we will traverse the whole string and repeat the above steps
18+
in the end if the stack has any elements in it, this signals the number of brackets we would need to remove
19+
*/
20+
int RemoveBrackets(string str)
21+
{
22+
stack <char> list;
23+
24+
for (int x = 0; x < str.length(); x++)
25+
{
26+
if (str[x] == '(')
27+
{
28+
list.push(str[x]);
29+
}
30+
else if (str[x] == ')')
31+
{
32+
if (!list.empty() && list.top() == '(')
33+
{
34+
list.pop();
35+
}
36+
else
37+
{
38+
list.push(str[x]);
39+
}
40+
}
41+
}
42+
43+
return list.size();
44+
}
45+
46+
int main()
47+
{
48+
cout << RemoveBrackets("(())()(((") << endl; // 3
49+
cout << RemoveBrackets("(()(") << endl; // 2
50+
cout << RemoveBrackets("(()))") << endl; // 1
51+
cout << RemoveBrackets("))(()))") << endl; // 3
52+
cout << RemoveBrackets("(())") << endl; // 0
53+
return 0;
54+
}

Debug/Fun Practice.log

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
Build started 7/31/2017 5:46:24 PM.
1+
Build started 8/29/2017 3:48:41 PM.
22
1>Project "C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Fun Practice\Fun Practice.vcxproj" on node 2 (Build target(s)).
33
1>ClCompile:
4-
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt 77_PalindromeSwapper.cpp
5-
77_PalindromeSwapper.cpp
6-
1>c:\users\gutty333\documents\visual studio 2013\projects\fun practice\fun practice\77_palindromeswapper.cpp(38): warning C4018: '<' : signed/unsigned mismatch
4+
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt 78_RemoveBrackets.cpp
5+
78_RemoveBrackets.cpp
6+
1>c:\users\gutty333\documents\visual studio 2013\projects\fun practice\fun practice\78_removebrackets.cpp(24): warning C4018: '<' : signed/unsigned mismatch
77
Link:
8-
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Debug\Fun Practice.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Debug\Fun Practice.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Debug\Fun Practice.lib" /MACHINE:X86 Debug\77_PalindromeSwapper.obj
8+
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Debug\Fun Practice.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Debug\Fun Practice.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Debug\Fun Practice.lib" /MACHINE:X86 Debug\78_RemoveBrackets.obj
99
Fun Practice.vcxproj -> C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Debug\Fun Practice.exe
1010
1>Done Building Project "C:\Users\gutty333\Documents\Visual Studio 2013\Projects\Fun Practice\Fun Practice\Fun Practice.vcxproj" (Build target(s)).
1111

1212
Build succeeded.
1313

14-
Time Elapsed 00:00:01.33
14+
Time Elapsed 00:00:03.18
12.5 KB
Binary file not shown.
830 Bytes
Binary file not shown.
850 Bytes
Binary file not shown.
-12 Bytes
Binary file not shown.
-12 Bytes
Binary file not shown.
-6 Bytes
Binary file not shown.

Debug/vc120.idb

8 KB
Binary file not shown.

0 commit comments

Comments
 (0)