Advertisement
dyamondz

Control C501B - P96293

Dec 28th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. void ordena_per_seleccio(vector<string>& v, int m){
  6.     if(m>0){
  7.         string max = v[0];
  8.         int pos = 0;
  9.         for (int i = 1; i <= m; ++i) {
  10.             if (v[i] > max) {
  11.                 max = v[i];
  12.                 pos = i;
  13.             }
  14.         }
  15.         v[pos] = v[m];
  16.         v[m] = max;
  17.         return ordena_per_seleccio(v, m-1);
  18.     }
  19. }
  20.  
  21. int main(){
  22.     int n;
  23.     cin>>n;
  24.     if(n>0){
  25.         vector<string> s(n);
  26.         for(int i=0;i<n;++i) cin>>s[i];
  27.         ordena_per_seleccio(s,n-1);
  28.         for(int i=0;i<n;++i){
  29.             cout<<s[i];
  30.             if(i!=n-1) cout<<',';
  31.         }
  32.     }
  33.     cout<<endl;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement