Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @ raj.nishant360@gmail.com
And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Saturday, March 8, 2014

EMTY2-Can You Make It Empty

Can You Make It Empty

below given code is for EMTY2 spoj or Can You Make It Empty spoj.
no need of explanation easy one;
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
class stack
{
public:
 char st[200000];
 int top;
 void push(char a){
  st[++top]=a;
 }
 void del(int pos)
 {
  for(int i=pos;i<top;i++)
   st[i]=st[i+1];
  st[top]==NULL;
  top--;
 }
};
int main()
{
 int t;
 scanf("%d  ",&t);
 for(int k=1;k<=t;k++)
 {
  stack d;
  d.top=-1;
  char s[200000];
  scanf("%s",s);
  int i=0,size;
  while(s[i]!='\0')
  {
   d.push(s[i]);
   if(d.top>=2){
    size=d.top;
    if(d.st[size-2]==49 && d.st[size-1]==48 && d.st[size]==48){
     d.del(size);
     d.del(size-1);
     d.del(size-2);
    }
   }
   i++;
  }
  if(d.top==-1)
   printf("Case %d: yes\n",k);
  else
   printf("Case %d: no\n",k);
 }
 return 0;
}