Advertisement
Guest User

lab_3

a guest
Mar 27th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class T>
  5. void enter(T &n) {
  6.     while (!(cin >> n) || ((cin.rdbuf()->in_avail())>1))
  7.     {
  8.         cout << "Data were incorrect.\nTry again.\n";
  9.         cin.clear();
  10.         while (cin.get() != '\n');
  11.     }
  12.     cin.clear();
  13.     while (cin.get() != '\n');
  14. }
  15.  
  16.  
  17.  
  18.  
  19. void main() {
  20.     int i = 0, n;
  21.     char * arrChar;
  22.     cout << "Enter size of array\n";
  23.     enter(n);
  24.     cout << "Enter please your text:\n";
  25.     arrChar = new char[n];
  26.     cin.getline(arrChar,n);
  27.     cout << "Your sorted array:\n";
  28.  
  29.     for (i = 0; i < n; ++i) {
  30.         if (arrChar[i] >= '0' && arrChar[i] <= '9')
  31.             cout << arrChar[i];
  32.         if (arrChar[i] == '\0') break;
  33.     }
  34.  
  35.     for (i = 0; i < n; ++i) {
  36.         if (!(arrChar[i] >= '0' && arrChar[i] <= '9'))
  37.             cout << arrChar[i];
  38.         if (arrChar[i] == '\0') break;
  39.     }
  40.     system("pause");
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement