Habsburg

prvi

Apr 26th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int N  = 0;
  6.     do {
  7.         cout << "Upisite N: ";
  8.         cin >> N;
  9.     }while(N <= 0);
  10.     int poljeV[N];
  11.     string poljeK[N];
  12.    
  13.     for(int i = 0; i < N ; ++i) {
  14.         cout << "Upisite " << i+1 << ". element: znak: ";
  15.         cin >>poljeK[i];
  16.        
  17.         cout << "Upisite " << i+1 << ". element: broj: ";
  18.         cin >>poljeV[i];
  19.     }
  20.    
  21.     for(int i = 1; i < N; ++i) {
  22.         int j = i;
  23.         while( j > 0 && poljeV[j] < poljeV[j-1]) {
  24.             swap(poljeV[j], poljeV[j-1]);
  25.             swap(poljeK[j], poljeK[j-1]);
  26.             --j;
  27.         }
  28.     }
  29.    
  30.     for(int i = 0; i < N; ++i) {
  31.         for(int j = 0; j < poljeV[i]; ++j)
  32.             cout << poljeK[i];
  33.         cout << endl;
  34.     }
  35.    
  36.    
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment