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("tukor.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;
- }
- void epit()
- {
- for(int i=0;i<=N;i++)
- A[i][i]=1;
- for(int i=0;i<=N;i++)
- {
- if(S[i]==S[i+1])
- A[i][i+1]=1;
- else
- A[i][i+1]=2;
- }
- for(int ko=2;ko<=N;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);
- }
- }
- }
- int main()
- {
- f>>S;
- N=strlen(S);
- epit();
- nyomtat();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement