Advertisement
O_Egor

Algo

Jan 17th, 2020
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <numeric>
  4. #include <cmath>
  5. #include <vector>
  6. using namespace std;
  7.  
  8. double sr;
  9.  
  10. void pred (long long &a)
  11. {
  12.     long long p(1), b = a;
  13.     while(b)
  14.     {
  15.         p*=b%10;
  16.         b/=10;
  17.     }
  18.     a+=p;
  19. }
  20.  
  21. long long sum (long long a)
  22. {
  23.     long long s(0);
  24.     while(a)
  25.     {
  26.         s+=a%10;
  27.         a/=10;
  28.     }
  29.     return s;
  30. }
  31.  
  32. bool sortPred(long long a, long long b)
  33. {
  34.     return (sum(a)<sum(b));
  35. }
  36. int main()
  37. {
  38.     int n;
  39.     cin>>n;
  40.  
  41.     vector <long long> v(n);
  42.     for(int i = 0; i < n ; ++i)
  43.         cin >> v[i];
  44.     ///1
  45.     for_each(v.begin(),v.end(),pred);
  46.  
  47.     for(int i = 0; i < n; ++i)
  48.         cout << v[i] << ' ';
  49.     cout << '\n';
  50.  
  51.     sort(v.begin(),v.end(),sortPred);
  52.  
  53.     for(int i = 0; i < n; ++i)
  54.         cout << v[i] << ' ';
  55.     cout << '\n';
  56.    
  57.     /**2if(all_of(v.begin(), v.end(), [](int i){return i % 2 == 0}))
  58.     {
  59.         sr = accumulate(v.begin(), v.end(), 0)/(n*1.);
  60.         int c = count_if(v.begin(), v.end(), [](int i){return i < sr; });
  61.         cout << "Kolichestvo elementov >" << sr <<" : " << c;
  62.     }
  63.     else
  64.         cout << "Ne vse elemnti chetnie.";**/
  65.    
  66.     /**3vector <int> ras(n);
  67.     adjacent_difference(v.begin(), v.end(), ras.begin());
  68.    
  69.     for(int i = 0; i < n; ++i)
  70.         cout << ras[i] << ' ';
  71.     cout << '\n';
  72.    
  73.     ras.resize(unique(ras.begin(), ras.end()) - ras.begin());
  74.     int szr = ras.size();
  75.    
  76.     for(int i = 0; i < szr; ++i)
  77.         cout << ras[i] << ' ';**/
  78.        
  79.     /**4vector <char> v(n);
  80.     for(int i = 0; i < n; ++i)
  81.         cin >> v[i];
  82.     int k;
  83.     cin >> k;
  84.    
  85.     while(k--)
  86.     {
  87.         int c;
  88.         cin >> c;
  89.        
  90.         vector <char> v1(c);
  91.         for(int i = 0; i < n; ++i)
  92.             cin >> v1[i];
  93.         cout << '\n';
  94.        
  95.         if(includes(v.begin(), v.end(), v1.begin(), v1.end())
  96.             cout << "Yavlyaetsya podmnojestvom.\n";
  97.         else
  98.             cout << "Ne yavlyaetsya podmnojestvom.\n";
  99.     }
  100.     **/
  101.    
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement