Mai intai trebuie sa te autentifici.
Cod sursa(job #156218)
Utilizator | Data | 12 martie 2008 13:42:41 | |
---|---|---|---|
Problema | Lampa | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.35 kb |
#include<fstream.h>
#include<string.h>
int main()
{
long j,k; int n;
long m,i;
char s[60000];
ifstream f("lampa.in");
f>>n>>m;
f>>s;
f.close();
char s1[10200],s2[10200],s3[10200],s4[10200];
s1[0]='1';s2[0]='2';s3[0]='1';s3[1]='2';s1[1]=s2[1]=s3[2]=0;
for (i=4;i<=n;i++)
{
strcpy(s4,s2);
strcat(s4,s3);
strcpy(s1,s2);
strcpy(s2,s3);
strcpy(s3,s4);
}
long nr1=0,nr2=0;
for (i=0;i<strlen(s3);i++)
if (s3[i]=='1') nr1++;
else nr2++;
long p;char c1[60000],c2[60000];c1[0]=0;c2[0]=0;
long h;int sw=0;
for (i=1;i<=m/nr1 && !sw;i++)
if ((m-nr1*i)%nr2==0) {
p=(m-nr1*i)/nr2;
if (s3[0]=='1') {
strncpy(c1,s,i);
strncpy(c2,s,i+p);
c1[i]=0;c2[i+p]=0;
strrev(c2);
c2[p]=0;
strrev(c2);
}
else {
strncpy(c2,s3,i);
strncpy(c1,s3,i+p);
strrev(c1);
strncpy(c1,c1,p);
strrev(c1);
}
k=i+p;
for (j=2;j<strlen(s3) && !sw;j++)
{
if (s3[j]=='1') for (h=0;h<strlen(c1)&&!sw;h++)
if (c1[h]!=s[k++]) sw=1;
if (s3[j]=='2') for (h=0;h<strlen(c2)&&!sw;h++)
if (c2[h]!=s[k++]) sw=1;
}
if (sw==0) sw=1;
else sw=0;
}
ofstream g("lampa.out");
if (sw==0) g<<-1;
else g<<c1<<endl<<c2;
g.close();
return 0;
}