Cod sursa(job #399314)

Utilizator tiger.snow1Iacob Andrei tiger.snow1 Data 20 februarie 2010 11:40:22
Problema Hotel Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include<fstream>
#include<string>
using namespace std;
#define N 100001
ifstream in("hotel.in");
ofstream out("hotel.out");
int n;
char cam[N];
char s[N],*pp,*q;

int secv()
{ unsigned int lmax=0;
    strncpy(s,cam,n);
	s[n]='\0';
  pp=strchr(s,'1');
  while(pp)
   { if(pp-s>lmax)
	    lmax=pp-s;
	 q=strchr(pp,'0');
	 if (q) 
	   {strcpy(s,q);
	    pp=strchr(s,'1');
       }
	 else 
		{
         s[0]='\0';
		 pp=0; 
	    }
   }
 if(strlen(s)>lmax)  
	  lmax=strlen(s);
   
return lmax;	
}
int main()
{
    int p,c,k,t;
    in>>n>>p;
    int i;
	//strset(cam,'0');
	for(int i=0;i<n;i++) cam[i]='0';
    for(i=1;i<=p;i++)
    {
        in>>c;
        if(c==1)
        {
            in>>k>>t;
            for(int j=k-1;j<=k+t-2;j++)
                cam[j]='1';
        }
        if(c==2)
        {
            in>>k>>t;
            for(int j=k-1;j<=k+t-2;j++)
                cam[j]='0';
        }
        if(c==3)
        {
            out<<secv()<<'\n';
        }
    }
    in.close();
    out.close();
    return 0;
}