Guest User

Untitled

a guest
Jul 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <locale.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <ctype.h>
  7. #include <string.h>
  8. #include <string>
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.     setlocale(LC_ALL, "Russian");
  15.  
  16.     const int LENGTH = 20;
  17.  
  18.     char input[] = "Qr27wp,d(6^3wAKl.?gD"; // 20 символов
  19.     char output[LENGTH];
  20.     printf("Входная строка: %s\n", input);
  21.  
  22.     int curr_index = 0; // Текущий индекс выходного массива
  23.  
  24.     // Поиск всех цифр
  25.     for(int i = 0; i < LENGTH; i++)
  26.     {
  27.         // Символ в массиве
  28.         char ch = input[i];
  29.  
  30.         if(isdigit(ch))
  31.         {
  32.             output[curr_index] = ch;
  33.             curr_index++;
  34.         }
  35.     }
  36.  
  37.     // Поиск всех букв
  38.     for(int i = 0; i < LENGTH; i++)
  39.     {
  40.         // Символ в массиве
  41.         char ch = input[i];
  42.  
  43.         if(isalpha(ch))
  44.         {
  45.             output[curr_index] = ch;
  46.             curr_index++;
  47.         }
  48.     }
  49.  
  50.     // Поиск остальных символов
  51.     for(int i = 0; i < LENGTH; i++)
  52.     {
  53.         // Символ в массиве
  54.         char ch = input[i];
  55.  
  56.         if(!isdigit(ch) && !isalpha(ch))
  57.         {
  58.             output[curr_index] = ch;
  59.             curr_index++;
  60.         }
  61.     }
  62.  
  63.     printf("Выходная строка: ");
  64.     for(int i = 0; i < LENGTH; i++)
  65.     {
  66.         cout << output[i];
  67.     }
  68.     cout << endl;
  69.    
  70.     return 0;
  71. }
Add Comment
Please, Sign In to add comment