Advertisement
a53

cuvant2

a53
Dec 30th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3. using namespace std;
  4. char s[256];
  5. int solutie,lungmaxsecv=0;
  6.  
  7. void citire()
  8. {
  9. ifstream f("cuvant2.in");
  10. f>>s;
  11. f.close();
  12. }
  13.  
  14. bool palindrom(int st,int dr)
  15. {
  16. while(st<dr)
  17. {
  18. if(s[st]!=s[dr])
  19. return false;
  20. st++;
  21. dr--;
  22. }
  23. return true;
  24. }
  25.  
  26. void afisare()
  27. {
  28. ofstream g("cuvant2.out");
  29. g<<solutie<<' '<<lungmaxsecv;
  30. g.close();
  31. }
  32.  
  33. int main()
  34. {
  35. citire();
  36. int lungimesir=strlen(s);
  37. int i,j,s[256],nrminsecv;
  38. for(i=0;i<lungimesir;++i)
  39. if(palindrom(0,i))
  40. {
  41. s[i]=1;
  42. lungmaxsecv=max(lungmaxsecv,i+1);
  43. }
  44. else
  45. {
  46. nrminsecv=257;
  47. for(j=0;j<i;++j)
  48. if(palindrom(j+1,i)&&s[j]<nrminsecv)
  49. {
  50. nrminsecv=s[j];
  51. lungmaxsecv=max(lungmaxsecv,i-j);
  52. }
  53.  
  54. s[i]=nrminsecv+1;
  55. }
  56. solutie=s[lungimesir-1];
  57. afisare();
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement