fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define maxx 100
  4. char stacks[maxx],str[maxx];
  5. int top=-1,v[maxx];
  6. int push(char stacks[maxx],char c){
  7. if(top==maxx)
  8. return 0;
  9. else
  10. if(c==stacks[top]) return 0;
  11. top++;
  12. stacks[top]=c;
  13. }
  14. int pop(char stacks[maxx]){
  15. if(top==-1)
  16. return 0;
  17. else
  18. char x=stacks[top];
  19. top--;
  20. }
  21. void srs(int i,int s,int c){
  22. for(int j=0;j<s;j++){
  23. if(top==-1){
  24. push(stacks,str[j]);
  25. }
  26. else{
  27. if(str[j]!=stacks[top]){
  28. if(c==2){
  29. pop(stacks);
  30. }
  31. push(stacks,str[j]);
  32. c=1;
  33. }
  34. else{
  35. c++;
  36. if(c==2){
  37. pop(stacks);
  38. }
  39. c=1;
  40. }
  41. }
  42. }
  43. }
  44. void display (char stacks[])
  45. { int i;
  46. if (top == -1)
  47. printf ("Empty String");
  48. else
  49. { for (i=0; i<=top; i++)
  50. printf ("%c",stacks[i]);
  51. }
  52. printf ("\n");
  53. }
  54. int main(){
  55. int s,z,c=1;
  56. cin>>str;
  57. s=strlen(str);
  58. srs(0,s,c);
  59. display(stacks);
  60. }
  61.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Empty String