Advertisement
Guest User

tukorszavak

a guest
Feb 27th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 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("tukor.be");
  11.  
  12. void nyomtat()
  13. {
  14. for(int i=0;i<N;i++)
  15. {
  16. cout.width (3);
  17. cout<<S[i];
  18. }
  19. cout<<endl;
  20. for(int i=0;i<N;i++)
  21. {
  22.  
  23. for(int j=0;j<N;j++)
  24. {
  25. cout.width (3);
  26. cout<<A[i][j];
  27. }
  28. cout<<endl;
  29.  
  30. }
  31. }
  32.  
  33. int Min(int sor, int oszlop)
  34. {
  35. int j=sor;
  36. int i=sor+1;
  37. int s=101;
  38. while(j<oszlop)
  39. {
  40. if(A[sor][j]+A[i][oszlop]<s)
  41. s=A[sor][j]+A[i][oszlop];
  42. j++;
  43. i--;
  44. }
  45. return s;
  46. }
  47.  
  48. void epit()
  49. {
  50. for(int i=0;i<=N;i++)
  51. A[i][i]=1;
  52. for(int i=0;i<=N;i++)
  53. {
  54. if(S[i]==S[i+1])
  55. A[i][i+1]=1;
  56. else
  57. A[i][i+1]=2;
  58. }
  59. for(int ko=2;ko<=N;ko++)
  60. {
  61. int i=0;
  62. for(int j=ko;j<=N-1;j++)
  63. {
  64. if(S[i]==S[j] && A[i+1][j-1]==1)
  65. A[i][j]=1;
  66. else
  67. A[i][j]=Min(i,j);
  68. }
  69. }
  70.  
  71. }
  72. int main()
  73. {
  74. f>>S;
  75. N=strlen(S);
  76. epit();
  77. nyomtat();
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement