fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 1000;
  5. const int TEN = 10;
  6.  
  7. int reverseNum(int num) {
  8. int reverse = 0;
  9. while (num) {
  10. reverse = reverse * TEN + num % TEN;
  11. num /= TEN;
  12. }
  13. return reverse;
  14. }
  15.  
  16. int existAllReverses(int fr[]) {
  17. for (int i = 0; i < MAX_SIZE; ++i) {
  18. if (fr[i] % TEN != 0 && fr[i] != fr[reverseNum(i)]) {
  19. return 1;
  20. }
  21. }
  22. return -1;
  23. }
  24.  
  25. int main() {
  26. int n, fr[MAX_SIZE] = {0};
  27. cin >> n;
  28. for (int i = 0; i < n; ++i) {
  29. int currentNum;
  30. cin >> currentNum;
  31. ++fr[currentNum];
  32. }
  33. int order = existAllReverses(fr);
  34. if (order > 0) {
  35. for (int i = 0; i < MAX_SIZE; ++i) {
  36. if (fr[i]) {
  37. cout << i << ' ';
  38. }
  39. }
  40. } else {
  41. for (int i = MAX_SIZE - 1; i >= 0; --i) {
  42. if (fr[i]) {
  43. cout << i << ' ';
  44. }
  45. }
  46. }
  47. return 0;
  48. }
Success #stdin #stdout 0s 5284KB
stdin
4
12 14 21 41
stdout
41 21 14 12