Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Se citesc un nr. cu max 18 cifre. Verificati daca cu cifrele nr. citit se pooate forma un palindrom, daca da,
- //afisati cel mai mare si cel mai mic palindrom.
- #include <iostream>
- using namespace std;
- int main()
- {
- long long x,fw[10]={0,0,0,0,0,0,0,0,0,0},nr[19],i,k,imp=-1,kk=0,j,v[100];
- cout<<"x= ";cin>>x;
- while (x)
- {
- fv[x%10]++;
- kk++;
- x=x/10;
- }
- for (i=0;i<=9;i++)
- {
- if(fv[i]%2==1)
- k++;imp=i;
- }
- if (k>1)
- {cout<<"NU";
- return 0;
- }
- else
- cout<<"DA"<<'\n';
- // construim palindromul cel mai mic. TEMA: De facut cel mai mare.
- k=0;
- for (cif=0;cif<=9;cif++)
- for (i=1;i<=fv[cif]/2;i++)
- {
- k++;
- nr[k]=cif;
- }
- if (imp!=-1)
- {
- k++;
- nr[k]=imp;
- }
- if (nr[1]==0)
- {
- i=2;
- while (v[i]==0)
- i++;
- v[1]=v[i];
- v[i]=0;
- }
- for (i=1,j=kk;i<j;i++,j--)
- nr[j]=nr[i];
- for (i=1;i<=kk;i++)
- cout<<nr[i];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement