Suoritettu

C++ code using data structures 2

The task is to write a function that checks if strings are balanced. Your code has to have a function named is_balanced which takes one argument: a std::string and returns a boolean. It should return true if the string is balanced, and false otherwise.

The function has to read the string character by character.

The function does not read the string multiple times.

If the function reads a character ', it ignores next characters until it reads the next '.

If the function reads the character ", it ignores next characters until it reads the next " character.

If the function reads the character ( or [, it pushes it on top of a stack.

If the function reads a )it checks the top of the stack and if it is equal to (, it deletes the topmost element of the stack -- otherwise it returns false.

If the function reads a ]it checks the top of the stack and if it is equal to [, it deletes the topmost element of the stack -- otherwise it returns false.

It ignores all other characters.

If after reading the whole string the stack is empty then the function returns true. If it is not empty, the function has to return false.

std::string s = "asdf";

std::cout << std::boolalpha;

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "()";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "([])";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "([)]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[()]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[()";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[(";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[(([])[()])]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[(' ')]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[('[')]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[('[()')]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "[('[()')(\")\")]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "\"()[]";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "\"'''\"";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "'''";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "\"\"\"";

std::cout << s << ": " << is_balanced(s) << std::endl;

s = "'\"'\"\"";

std::cout << s << ": " << is_balanced(s) << std::endl;

Should print:

asdf: true

(): true

([]): true

([)]: false

[()]: true

[(): false

[(: false

[(([])[()])]: true

[(' ')]: true

[('[')]: true

[('[()')]: true

[('[()')(")")]: true

"()[]: false

"'''": true

''': false

""": false

'"'"": true

Taidot: C-ohjelmointi, C++ -ohjelmointi, tietojärjestelmäarkkitehtuuri

Näytä lisää: data structure program examples, c++ stack program example, data structure programs in c++ pdf, stack in data structure, data structures using c++ programs download, data structures programs in c++, data structures and algorithms in c++, c++ data structures book, sorting techniques in data structures using c, introduction to data structures using c, data structures with c using stl, data structures using c tutorial, data structures using c online tutorial, c algorithms and data structures, list project using data structures, project using data structures, project list using data structures, write search query using data structures java, java projects using data structures, reading using data excel

Tietoa työnantajasta:
( 0 arvostelua ) Lodz, Poland

Projektin tunnus: #17165181

Myönnetty käyttäjälle:

neos94

Hello, I am very experienced with algorithmic problem solving and can deliver this within minutes :) I have been in competitive programming for 8 years and I took part in International Olympiad in Informatics, which Lisää

zł60 PLN 1 päivässä
(0 Arvostelua)
0.0

13 freelanceria on tarjonnut keskimäärin %project_bid_stats_avg_sub_26% %project_currencyDetails_sign_sub_27% tähän työhön

liangjongai

Hi! I'm interesting your project very well. I am a full time devloper. I am mastering c++ and I'm a good Mathematician. And also I have many experience and good skill about algorithm development. Let's go ahead w Lisää

zł90 PLN 1 päivässä
(231 arvostelua)
7.1
bormaa

Dear sir, iam interested in your project i can finish it easily with high quality with least price because iam building my profile. I can provide many design which can satisfy your impression and achieve what you want. Lisää

zł75 PLN 1 päivässä
(8 arvostelua)
4.8
kalyanprakash4

please discuss .........................................................................................................................................................

zł105 PLN 2 päivässä
(16 arvostelua)
4.1
junaidlodhi6

i am an expert in c++... i can give you in 5 hours... looking forward to get some response... thanks!

zł90 PLN 1 päivässä
(16 arvostelua)
3.6
rabnawazjansher8

hi , i can do your C++ assignment .. and i have already done many assignments related to data structure. i have past experience of 3 years. let discuss over chat thanks

zł75 PLN 1 päivässä
(12 arvostelua)
3.4
Davepsingh23

Hello, I have my expertise in C++ and C and I can assure you that I have the right kind of experience and skills for this job. I have 6+ year of experience and these years I have created various projects like Dat Lisää

zł75 PLN 1 päivässä
(2 arvostelua)
2.8
zł40 PLN 0 päivässä
(1 arvostelu)
1.9
mashreghali

Hi, I have done a similar project before. I have good knowledge of C++ and data structures. I can do your project for you in 1 day.

zł75 PLN 1 päivässä
(1 arvostelu)
0.8
durgesh8527

Hello Sir/Mam, I have read your post requirement for the " task is to write a function that checks if strings are balanced. ". Now I have some questions to clear the things for this project. I am full time freelancer h Lisää

zł75 PLN 3 päivässä
(0 arvostelua)
0.0
zł30 PLN 1 päivässä
(0 arvostelua)
0.0
arazos

Hello, I wrote the code for the previous one just for fun. The code works completely fine for all inputs.

zł50 PLN 1 päivässä
(0 arvostelua)
0.0
kojecka

Greetings. I have experience teaching data structures and programming classes for a long time (15+ years). So, I have full confidence in delivering your code as required. Looking forward to working with you.

zł85 PLN 2 päivässä
(0 arvostelua)
0.0