Habsburg

4.

Feb 12th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. void cetvrti() {
  6.     int num;
  7.     cout << "Koliko rijeci zelize?: ";
  8.     cin >> num;
  9.     string poljeS[num];
  10.     for(int i = 0 ; i < num ; i++) {
  11.         cout << "Upisite " << i+1 << " rijec: ";
  12.         cin >> poljeS[i];
  13.     }
  14.     bool found = true;
  15.     while(found) {
  16.         found = false;
  17.         for(int i = 0 ; i < num-1 ; i++)
  18.             if(poljeS[i].size() < poljeS[i+1].size()) {
  19.                 swap(poljeS[i], poljeS[i+1]);
  20.                 found = true;
  21.             }
  22.     }
  23.    
  24.     found = true;
  25.     while(found) {
  26.         found = false;
  27.         for(int i = 0 ; i < num-1 ; i++)
  28.             if(poljeS[i].size() == poljeS[i+1].size() && poljeS[i] > poljeS[i+1]) {
  29.                 swap(poljeS[i], poljeS[i+1]);
  30.                 found = true;
  31.             }
  32.     }
  33.     for(int i = 0 ; i < num ; i++)
  34.         cout << poljeS[i] << " ";
  35.    
  36. }
  37.  
  38. int main() {
  39.     cetvrti();
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment