0% found this document useful (0 votes)
772 views

CoderByte Challange 7 Soucre Code

This C++ code defines a SimpleSymbols function that takes a string as a parameter and returns a string indicating whether the string contains only '+' and '=' symbols surrounded by other '+' and '=' symbols. It loops through the string, checking that each character is '+' or '=' and is surrounded by the same symbol on both sides, and returns "true" if this is true for all characters or "false" if any character violates this condition.

Uploaded by

dejan_032
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
772 views

CoderByte Challange 7 Soucre Code

This C++ code defines a SimpleSymbols function that takes a string as a parameter and returns a string indicating whether the string contains only '+' and '=' symbols surrounded by other '+' and '=' symbols. It loops through the string, checking that each character is '+' or '=' and is surrounded by the same symbol on both sides, and returns "true" if this is true for all characters or "false" if any character violates this condition.

Uploaded by

dejan_032
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream> #include <string> using namespace std; string SimpleSymbols(string str) { // code goes here int len=str.

length(); bool result; int current=1; if((str[0]!='+') || (str[0]!='=') || (str[len]!='+') || (str[len]!='=')) { str="false"; return str; } while (current<str.length()-1) { if((str[current]!='+' || str[current]!='=') && ((str[current-1]! ='+' && str[current+1]!='+') || (str[current-1]!='=' && str[current+1]!='='))) { result=true; current +=2; } else { result=false; break; } } if(result) str="true"; else str="false"; return str; } int main() { // keep this function call here cout << SimpleSymbols("+d+=3=+s+"); return 0; }

You might also like