Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Minimalis szamu tukorszora bontas
- #include <iostream>
- #include <fstream>
- #include <string.h>
- using namespace std;
- int N,A[100][100];
- char S[100];
- ifstream f("szavak.be");
- void Nyomtat()
- {
- for(int i=0;i<N;i++)
- {cout.width(3);
- cout<<S[i];
- }
- cout<<endl;
- for(int i=0;i<N;i++)
- {
- for(int j=0;j<N;j++)
- {
- cout.width(3);
- cout<<A[i][j];
- }
- cout<<endl;
- }
- }
- int Min(int sor, int oszlop)
- {
- int j=sor;
- int i=sor+1;
- int s=101;
- while(j<oszlop)
- {
- if(A[sor][j]+A[i][oszlop]<s)
- s=A[sor][j]+A[i][oszlop];
- j++;i++;
- }
- return s;
- }
- int VisszaMin(int sor, int &j, int oszlop, int &i)
- {
- j=sor;
- i=sor+1;
- while(j<oszlop)
- {
- if(A[sor][j]+A[i][oszlop]==A[sor][oszlop])
- return 1;
- else
- {
- j++;i++;
- }
- }
- return 1;
- }
- void Epit()
- {
- //Foatlo
- for(int i=0;i<=N-1;i++)
- A[i][i]=1;
- //Elsoatlo
- for(int i=0;i<=N-2;i++)
- if(S[i]==S[i+1])
- A[i][i+1]=1;
- else
- A[i][i+1]=2;
- //tobbi atlo
- for(int ko=2;ko<=N-1;ko++)
- {
- int i=0;
- for(int j=ko;j<=N-1;j++)
- {
- if(S[i]==S[j] && A[i+1][j-1]==1)
- A[i][j]=1;
- else
- A[i][j]=Min(i,j);
- i++;
- }
- }
- }
- void Kiir(int e, int u)
- {
- for(int i=e;i<=u;i++)
- cout<<S[i];
- cout<<endl;
- }
- void Visszaszamol(int i, int j)
- {
- if(A[i][j]==1)
- Kiir(i,j);
- else
- {
- int i1, j1;
- VisszaMin(i,j1, j,i1);
- Visszaszamol(i,j1);
- Visszaszamol(i1,j);
- }
- }
- int main()
- {
- f>>S;
- N=strlen(S);
- Epit();
- Nyomtat();
- Visszaszamol(0,N-1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement