Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <cstring>
- using namespace std;
- char s[256];
- int solutie,lungmaxsecv=0;
- void citire()
- {
- ifstream f("cuvant2.in");
- f>>s;
- f.close();
- }
- bool palindrom(int st,int dr)
- {
- while(st<dr)
- {
- if(s[st]!=s[dr])
- return false;
- st++;
- dr--;
- }
- return true;
- }
- void afisare()
- {
- ofstream g("cuvant2.out");
- g<<solutie<<' '<<lungmaxsecv;
- g.close();
- }
- int main()
- {
- citire();
- int lungimesir=strlen(s);
- int i,j,s[256],nrminsecv;
- for(i=0;i<lungimesir;++i)
- if(palindrom(0,i))
- {
- s[i]=1;
- lungmaxsecv=max(lungmaxsecv,i+1);
- }
- else
- {
- nrminsecv=257;
- for(j=0;j<i;++j)
- if(palindrom(j+1,i)&&s[j]<nrminsecv)
- {
- nrminsecv=s[j];
- lungmaxsecv=max(lungmaxsecv,i-j);
- }
- s[i]=nrminsecv+1;
- }
- solutie=s[lungimesir-1];
- afisare();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement