Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- // input the string
- string str;
- cin>>str;
- // if we've seen an open parentheses
- bool open_eye = false;
- // if we've seen a close parentheses
- bool close_eye = false;
- // number of bars seen before the eye
- int pre_eye = 0;
- // number of bars seen after the eye
- int post_eye = 0;
- // loop through indices
- for(int i=0;i<str.size();i++)
- {
- // if we see a bar
- if(str[i]=='|')
- {
- // if we're looking for a close parentheses, we need to fix it
- if(open_eye)
- {
- cout << "fix\n";
- return 0;
- }
- // increment corresponding operator
- if(!close_eye) pre_eye++;
- else post_eye++;
- }
- // if we see close parentheses
- else if(str[i]==')')
- {
- // if we are not looking to close the eye, we need to fix
- if(!open_eye)
- {
- cout << "fix\n";
- return 0;
- }
- // close the eye
- open_eye = false;
- close_eye = true;
- }
- // if we see an open parentheses
- else
- {
- // if we already saw the eye, we need to fix
- if(open_eye || close_eye)
- {
- cout << "fix\n";
- return 0;
- }
- // open the eye
- open_eye = true;
- }
- }
- // if same number of bars before and after eye, it is correct
- if(pre_eye==post_eye) cout << "correct\n";
- // otherwise it needs to be fixed
- else cout << "fix\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment