daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. int main() {
  4.     using namespace std;
  5.     int k;
  6.     int n;
  7.     cout << "Podaj ilosc liczb do posortowania" << endl;
  8.     cin >> n;
  9.     int A[n + 1];
  10.     cout << "Podaj liczby do posortowania" << endl;
  11.     for (int i = 1; i <= n; i++) {
  12.         cin >> A[i];
  13.     }
  14.     int a = 0;
  15.     while (a < 1) {
  16.         cout << "Podaj dowolna liczbe wieksza lub rowna od wszystkich liczb do posortowania" << endl;
  17.  
  18.         cin >> k;
  19.         a = a + 1;
  20.         for (int i = 1; i <= n; i++) {
  21.             if (k < A[i]) {
  22.                 a = 0;
  23.                 cout << "Dana liczba nie jest wieksza od liczb do posortowania, sprobuj ponownie" << endl << endl;
  24.                 i = n;
  25.             }
  26.         }
  27.     }
  28.     int B[n + 1];
  29.     int C[k + 1];
  30.     cout << endl;
  31.     for (int i = 0; i <= k; i++) {
  32.         C[i] = 0;
  33.     }
  34.     for (int i = 1; i <= n; i++) {
  35.         C[A[i]] = C[A[i]] + 1;
  36.     }
  37.     for (int i = 1; i <= k; i++) {
  38.         C[i] = C[i] + C[i - 1];
  39.     }
  40.     int j = n;
  41.     for (int i = 0; i <= n; i++) {
  42.         B[i] = 0;
  43.     }
  44.     while (j >= 1) {
  45.         B[C[A[j]]] = A[j];
  46.         C[A[j]] = C[A[j]] - 1;
  47.         j = j - 1;
  48.     }
  49.     cout << "Posortowane liczby:" << endl << "[ ";
  50.     for (int i = 1; i <= n; i++) {
  51.         cout << B[i] << " ";
  52.     }
  53.     cout << "]";
  54.     return 0;
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top