Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. string wyraz;
  5. int tab[2010];
  6. int licznik;
  7. int a;
  8. int x = 1;
  9. int operacje = 0;
  10.  
  11. int main()
  12. {
  13. do
  14. {
  15. cin >> wyraz;
  16. if(wyraz[0] == '-')
  17. {
  18. return 0;
  19. }
  20. licznik = 0;
  21. operacje = 0;
  22. for(int i = 0 ; i < wyraz.size() ; i++)
  23. {
  24. a = 0;
  25. if(wyraz[0] == '}')
  26. {
  27. wyraz[0] = '{';
  28. licznik++;
  29. operacje++;
  30. a = 1;
  31. }
  32. if(a == 0)
  33. {
  34. if(wyraz[i] == '}' && licznik <= 0)
  35. {
  36. wyraz[i] = '{';
  37. licznik++;
  38. operacje++;
  39. }
  40. else if(wyraz[i] == '{' && licznik > 0)
  41. {
  42. wyraz[i] = '}';
  43. licznik--;
  44. operacje++;
  45. }
  46. else if(wyraz[i] == '{')
  47. {
  48. licznik++;
  49. }
  50. else
  51. {
  52. licznik--;
  53. }
  54. }
  55. }
  56. cout /*<< wyraz << "\n"*/ << x << ". " << operacje << "\n";
  57. x++;
  58. }while(wyraz[0] != '-');
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement