Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream fin("palindromsd.in");
- ofstream fout("palindromsd.out");
- bool palindrom(int x)
- {
- int y = 0, nr=x;
- while(nr!=0)
- {
- y = y*10 + nr%10;
- nr/=10;
- }
- return x==y;
- /* echivalent cu:
- if(x==y)
- return true;
- else
- return false;
- */
- }
- int main()
- {
- int ar[1001],x,j,i=0,a,nr,b,nr1=0;
- while(fin>>x){ar[++i]=x;}
- for(j=1;j<i;j++)
- {
- if(palindrom(ar[j]))
- {
- fout << ar[j] << " ";
- nr1++;
- }
- if(palindrom(ar[i]))
- {
- fout << ar[i] << " ";
- nr1++;
- }
- i--;
- }
- if(i == j && palindrom(ar[i]))
- {
- fout<<ar[i]<<" ";
- nr1++;
- }
- if(!nr1)fout<<"-1";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement