Cod sursa(job #2389100)

Utilizator TeoDiDiaconescu Teodora TeoDi Data 26 martie 2019 20:16:02
Problema Subsir Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 3.5 kb
#include <bits/stdc++.h>
char s[1001],t[1001];
int q,r;
int mat[501][2];
int f[100][501];
using namespace std;
ifstream fin("subsir.in");
ofstream fout("subsir.out");
void P(int);
void C(char,int);
int T(char);
int main()
{
    fin.getline(s,1000);
    fin.getline(t,1000);
    q=strlen(s);
    r=strlen(t);
    for(int i=0;i<100;i++) f[i][0]=1;
    for(int i=0;i<r;i++) C(t[i],i);
    P(q-1);
    int nax=0,ct=0;
    char v[501]="",l[501]="";
    for(int i=0;i<r;i++)
    {
        if(mat[i][0]>nax)
        {
            ct=1;
            nax=mat[i][0]; int j=i;
            v[0]=t[i]; int y=1;
            while(mat[j][1]) v[y++]=t[j],j=mat[j][1];
            v[y]=0;
        }
        else if(mat[i][0]==nax)
        {
            int j=i;
            l[0]=t[i]; int y=1;
            while(mat[j][1]) l[y++]=t[j],j=mat[j][1];
            l[y]=0;
            if(strcmp(l,v)!=0) ct++;
            ct%=666013;
        }
    }
    fout<<ct%666013<<' '<<nax;
    return 0;
}
void C(char c,int x)
{
    if(c=='a') f[1][f[1][0]]=x,f[1][0]++;
    else if(c=='b') f[2][f[2][0]]=x,f[2][0]++;
    else if(c=='c') f[3][f[3][0]]=x,f[3][0]++;
    else if(c=='d') f[4][f[4][0]]=x,f[4][0]++;
    else if(c=='e') f[5][f[5][0]]=x,f[5][0]++;
    else if(c=='f') f[6][f[6][0]]=x,f[6][0]++;
    else if(c=='g') f[7][f[7][0]]=x,f[7][0]++;
    else if(c=='h') f[8][f[8][0]]=x,f[8][0]++;
    else if(c=='i') f[9][f[9][0]]=x,f[9][0]++;
    else if(c=='j') f[10][f[10][0]]=x,f[10][0]++;
    else if(c=='k') f[11][f[11][0]]=x,f[11][0]++;
    else if(c=='l') f[12][f[12][0]]=x,f[12][0]++;
    else if(c=='m') f[13][f[13][0]]=x,f[13][0]++;
    else if(c=='n') f[14][f[14][0]]=x,f[14][0]++;
    else if(c=='o') f[15][f[15][0]]=x,f[15][0]++;
    else if(c=='p') f[16][f[16][0]]=x,f[16][0]++;
    else if(c=='q') f[17][f[17][0]]=x,f[17][0]++;
    else if(c=='r') f[18][f[18][0]]=x,f[18][0]++;
    else if(c=='s') f[19][f[19][0]]=x,f[19][0]++;
    else if(c=='t') f[20][f[20][0]]=x,f[20][0]++;
    else if(c=='u') f[21][f[21][0]]=x,f[21][0]++;
    else if(c=='v') f[22][f[22][0]]=x,f[22][0]++;
    else if(c=='w') f[23][f[23][0]]=x,f[23][0]++;
    else if(c=='x') f[24][f[24][0]]=x,f[24][0]++;
    else if(c=='y') f[25][f[25][0]]=x,f[25][0]++;
    else if(c=='z') f[26][f[26][0]]=x,f[26][0]++;
}

int T(char c)
{
    if(c=='a') return 1;
    else if(c=='b') return 2;
    else if(c=='c') return 3;
    else if(c=='d') return 4;
    else if(c=='e') return 5;
    else if(c=='f') return 6;
    else if(c=='g') return 7;
    else if(c=='h') return 8;
    else if(c=='i') return 9;
    else if(c=='j') return 10;
    else if(c=='k') return 11;
    else if(c=='l') return 12;
    else if(c=='m') return 13;
    else if(c=='n') return 14;
    else if(c=='o') return 15;
    else if(c=='p') return 16;
    else if(c=='q') return 17;
    else if(c=='r') return 18;
    else if(c=='s') return 19;
    else if(c=='t') return 20;
    else if(c=='u') return 21;
    else if(c=='v') return 22;
    else if(c=='w') return 23;
    else if(c=='x') return 24;
    else if(c=='y') return 25;
    else if(c=='z') return 26;
}

void P(int k)
{
    if(f[T(s[k])][0]>1)
    {
        for(int i=1;i<f[T(s[k])][0];i++)
        {
            int ct=1,u=0;
            for(int p=f[T(s[k])][i]+1;p<r;p++)
            {
                if(mat[p][0]!=0 && mat[p][0]>=ct) ct=mat[p][0]+1,u=p;
            }
            mat[f[T(s[k])][i]][0]=ct;
            mat[f[T(s[k])][i]][1]=u;
        }
    }
    if(k>0) P(k-1);
}