Đã hoàn thành

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

Kĩ năng: Lập trình C, Lập trình C++, Kiến trúc phần mềm

Xem nhiều hơn: 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

Về Bên Thuê:
( 0 nhận xét ) Lodz, Poland

ID dự án: #17165181

Được trao cho:

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 Thêm

zł60 PLN trong 1 ngày
(0 Đánh Giá)
0.0

13 freelancer đang chào giá trung bình zł71 cho công việc này

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 Thêm

zł90 PLN trong 1 ngày
(231 Nhận xét)
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. Thêm

zł75 PLN trong 1 ngày
(8 Nhận xét)
4.8
kalyanprakash4

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

zł105 PLN trong 2 ngày
(16 Nhận xét)
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 trong 1 ngày
(16 Nhận xét)
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 trong 1 ngày
(12 Nhận xét)
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 Thêm

zł75 PLN trong 1 ngày
(2 Nhận xét)
2.8
zł40 PLN trong 0 ngày
(1 Nhận xét)
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 trong 1 ngày
(1 Nhận xét)
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 Thêm

zł75 PLN trong 3 ngày
(0 Nhận xét)
0.0
zł30 PLN trong 1 ngày
(0 Nhận xét)
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 trong 1 ngày
(0 Nhận xét)
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 trong 2 ngày
(0 Nhận xét)
0.0