Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- string wyraz;
- int tab[2010];
- int licznik;
- int a;
- int x = 1;
- int operacje = 0;
- int main()
- {
- do
- {
- cin >> wyraz;
- if(wyraz[0] == '-')
- {
- return 0;
- }
- licznik = 0;
- operacje = 0;
- for(int i = 0 ; i < wyraz.size() ; i++)
- {
- a = 0;
- if(wyraz[0] == '}')
- {
- wyraz[0] = '{';
- licznik++;
- operacje++;
- a = 1;
- }
- if(a == 0)
- {
- if(wyraz[i] == '}' && licznik <= 0)
- {
- wyraz[i] = '{';
- licznik++;
- operacje++;
- }
- else if(wyraz[i] == '{' && licznik > 0)
- {
- wyraz[i] = '}';
- licznik--;
- operacje++;
- }
- else if(wyraz[i] == '{')
- {
- licznik++;
- }
- else
- {
- licznik--;
- }
- }
- }
- cout /*<< wyraz << "\n"*/ << x << ". " << operacje << "\n";
- x++;
- }while(wyraz[0] != '-');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement