Advertisement
Guest User

elooood

a guest
Feb 27th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. //Minimalis szamu tukorszora bontas
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string.h>
  5.  
  6. using namespace std;
  7.  
  8. int N,A[100][100];
  9. char S[100];
  10. ifstream f("szavak.be");
  11.  
  12. void Nyomtat()
  13. {
  14. for(int i=0;i<N;i++)
  15. {cout.width(3);
  16. cout<<S[i];
  17. }
  18. cout<<endl;
  19. for(int i=0;i<N;i++)
  20. {
  21. for(int j=0;j<N;j++)
  22. {
  23. cout.width(3);
  24. cout<<A[i][j];
  25. }
  26. cout<<endl;
  27. }
  28. }
  29. int Min(int sor, int oszlop)
  30. {
  31. int j=sor;
  32. int i=sor+1;
  33. int s=101;
  34. while(j<oszlop)
  35. {
  36. if(A[sor][j]+A[i][oszlop]<s)
  37. s=A[sor][j]+A[i][oszlop];
  38. j++;i++;
  39. }
  40. return s;
  41. }
  42. int VisszaMin(int sor, int &j, int oszlop, int &i)
  43. {
  44. j=sor;
  45. i=sor+1;
  46. while(j<oszlop)
  47. {
  48. if(A[sor][j]+A[i][oszlop]==A[sor][oszlop])
  49. return 1;
  50. else
  51. {
  52. j++;i++;
  53. }
  54. }
  55. return 1;
  56. }
  57. void Epit()
  58. {
  59. //Foatlo
  60. for(int i=0;i<=N-1;i++)
  61. A[i][i]=1;
  62. //Elsoatlo
  63. for(int i=0;i<=N-2;i++)
  64. if(S[i]==S[i+1])
  65. A[i][i+1]=1;
  66. else
  67. A[i][i+1]=2;
  68. //tobbi atlo
  69. for(int ko=2;ko<=N-1;ko++)
  70. {
  71. int i=0;
  72. for(int j=ko;j<=N-1;j++)
  73. {
  74. if(S[i]==S[j] && A[i+1][j-1]==1)
  75. A[i][j]=1;
  76. else
  77. A[i][j]=Min(i,j);
  78. i++;
  79. }
  80. }
  81. }
  82. void Kiir(int e, int u)
  83. {
  84. for(int i=e;i<=u;i++)
  85. cout<<S[i];
  86. cout<<endl;
  87. }
  88. void Visszaszamol(int i, int j)
  89. {
  90. if(A[i][j]==1)
  91. Kiir(i,j);
  92. else
  93. {
  94. int i1, j1;
  95. VisszaMin(i,j1, j,i1);
  96. Visszaszamol(i,j1);
  97. Visszaszamol(i1,j);
  98. }
  99. }
  100. int main()
  101. {
  102. f>>S;
  103. N=strlen(S);
  104. Epit();
  105. Nyomtat();
  106. Visszaszamol(0,N-1);
  107.  
  108. return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement