Cod sursa(job #1679871)

Utilizator MihneaGabrielMihnea-Gabriel Manolescu MihneaGabriel Data 8 aprilie 2016 12:14:46
Problema ADN Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
ifstream f("adn.in");
ofstream g("adn.out");
char x[30000],y[30000],z[30000],z1[30000];
int n;
int main()
{
    int j;
    char *p, *q;
    f>>n;
    f>>x;
    strcpy(z1,x);

    for (int i=2; i<=n; i++)
    {
        f>>y;
        strcpy(z,y);
        //vad daca y se afla la finalul lui x;

        if(strstr(x,z)==NULL)
        {
            j=strlen(y);

            while(1&& strlen(z)!=0)
            {
                p=strstr(x,z);
                if(p!=NULL)
                    if(strlen(p)==strlen(z))
                    {

                        break;
                    }
                z[strlen(z)-1]=NULL;

            }
        }

        strcpy(x+strlen(x),y+strlen(z));
        int k=strlen(x)+strlen(y+strlen(z));
        x[k]=NULL;
        strcpy(z,y);
        //vad daca y se afla la inceput de x; cea mai lunga ultima secventa din y o caut la inceput x
        p=strstr(z1,z);
        while(p==NULL && strlen(z)!=0)
        {

            strcpy(z,z+1);
            p=strstr(z1,z);
        }

        //adaug tot y, la inceput de x
        strcpy(y+(strlen(y)-strlen(z)),z1);

        strcpy(z1,y);

        if (strlen (z1)<strlen(x))
            strcpy(x,z1);
    }
    cout<<x;
}