Advertisement
Guest User

2009 - 36

a guest
Feb 17th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. *** 2009 - 36 ***
  2. ------------------------------------------------------
  3. #include <iostream>
  4. #include <fstream>
  5. using namespace std;
  6. int cifra(short int a)
  7.     {
  8.         short int c;
  9.         if(a==0) return 0;
  10.         while(a>0){
  11.             c=a%10;
  12.             if(c%2==0){
  13.                 return c;
  14.             }
  15.             a/=10;
  16.         }
  17.         return -1;
  18.     }
  19.  
  20. int main(){
  21.     ifstream cin("bac.txt");
  22.     short int n,a[9999]={},kcp,i;
  23.     kcp=0;
  24.     int nr;
  25.     cin>>n;
  26.     for(i=0;i<n;i++){
  27.         cin>>nr;
  28.         if(cifra(nr)!=-1){
  29.             a[kcp]=cifra(nr);
  30.             kcp++;
  31.         }
  32.     }
  33.     for(i=0;i<kcp-1;i++){
  34.         for(short int j=i;j<kcp;j++){
  35.                 if(a[i]<a[j]){
  36.                     swap(a[i],a[j]);
  37.                 }
  38.         }
  39.     }
  40.     for(i=0;i<kcp;i++){
  41.         cout<<a[i];
  42.     }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement