fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class ParenthesesDiv1Easy
  4. {
  5. public:
  6. vector <int> correct(string s);
  7.  
  8. };
  9. vector < int > ParenthesesDiv1Easy::correct(string S)
  10. {
  11. vector < int > stk;
  12. static vector < int > ret;
  13. int i ;
  14.  
  15. for(i=0;i<S.length();++i)
  16. {
  17. if(S[i]=='(')
  18. stk.push_back(i);
  19. else
  20. {
  21. if(stk.empty() || S[*stk.rbegin()]!='(')
  22. stk.push_back(i);
  23. else
  24. stk.pop_back();
  25. }
  26. }
  27.  
  28. if(stk.size()%2)
  29. {
  30. ret.push_back(-1);
  31. return ret;
  32. }
  33.  
  34. i = 0 ;
  35. while(i<(int)stk.size() && S[stk[i]]==')')
  36. ++i;
  37. --i;
  38. i = min((int)stk.size()/2-1,i);
  39. if(i!=-1)
  40. {
  41. ret.push_back(stk[0]);
  42. ret.push_back(stk[i]);
  43. }
  44.  
  45. i = (int)stk.size()-1;
  46. while(i>=0 && S[stk[i]]=='(')
  47. --i;
  48. ++i;
  49. i = max((int)stk.size()/2,i);
  50. if(i!=stk.size())
  51. {
  52. ret.push_back(stk[i]);
  53. ret.push_back(*stk.rbegin());
  54. }
  55. return ret;
  56. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/i586-linux-gnu/5/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty