Cod sursa(job #1358981)

Utilizator AlphaZoneRAlbert Ferencz AlphaZoneR Data 24 februarie 2015 20:48:56
Problema Potrivirea sirurilor Scor 24
Compilator cpp Status done
Runda Arhiva educationala Marime 1.45 kb
#include <fstream>
#include <string.h>
#define NMAX 20000

using namespace std;
    ifstream in("strmatch.in");
    ofstream out("strmatch.out");
    char A[NMAX];
    char B[NMAX];
    int C[NMAX][NMAX];
    int D[NMAX];
    int pos;
    void beolvas(){
        in >> A;
        in >> B;
    }

    void betolt(){
        for(int i = 0;i<strlen(A);i++){
            for(int j = 0 ; j<strlen(B);j++){
                if(A[i] == B[j]){
                    C[i][j] = C[i-1][j-1] +1;
               }
            }
        }

    }
    void kiir(){
        out << pos << endl;
        for(int i = 0;i<pos;i++){
            out << D[i] << " ";
        }
        out << endl;

    }
    void keres(){
        int max = 0;
        for(int i = 0;i<strlen(A);i++){
                for(int j = 0 ; j<strlen(B);j++){
                   if(C[i][j] > max){
                        max = C[i][j];
                   }
                }

            }
        for(int i = 0;i<strlen(A);i++){
                for(int j = 0 ; j<strlen(B);j++){
                  if(C[i][j] == max){
                    int x=i,y=j;
                    while(C[x][y] >= 1){
                        x--;y--;
                    }
                    D[pos] = y+1;
                    pos++;
                  }
                }

            }

    }


    int main(){
        beolvas();
        betolt();
        keres();
        kiir();


    }