Guest User

Untitled

a guest
Dec 10th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.32 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string.h>
  4.  
  5. #define ChLength 40
  6. #define ChLength1 40
  7. #define ChLength2 80
  8.  
  9. int main(){
  10.     setlocale(LC_ALL,"Russian");
  11.  
  12.     char ch[ChLength];
  13.     char result[ChLength];char result1[ChLength];
  14.     char *pch[ChLength/2];
  15.     char ch1[ChLength];
  16.     char *pch1[ChLength/2];
  17.     char itog[ChLength2];
  18.     int ind1;
  19.     int ind2;
  20.  
  21.  
  22.    
  23.     //считывание1
  24.     int i;
  25.     printf("Введите стоку из %d символов:\n", ChLength);
  26.     for (i=0;i < ChLength && ch[i-1] != '\n'; i++){
  27.         ch[i] = getchar();
  28.     }
  29.     ch[i-1]='\0';
  30.  
  31.     //парсинг строки1
  32.     pch[0] = strtok (ch," ");
  33.     for (int i = 1; pch[i-1] != NULL; i++){
  34.         pch[i] = strtok (NULL, " ");
  35.     }
  36.  
  37.     //реальная длина массива1
  38.     int end = 0;
  39.     while(pch[end++] != '\0') { }
  40.     end-=2;
  41.  
  42.     //сортировка1
  43.     printf("по возрастанию: \n");
  44.     for(int i = 0; i < end; i++){
  45.         for(int j = end; j > i; j--){
  46.             if (*pch[i] > *pch[j])
  47.             {
  48.                 char *temp = pch[i];
  49.                 pch[i] = pch[j];
  50.                 pch[j] = temp;
  51.             }
  52.         }
  53.     }
  54.    //сложение строк1
  55.     strcpy(result,pch[0]);
  56.     for (int i = 1; i <= end; i++){
  57.         strcat(result, " ");
  58.         strcat(result, pch[i]);
  59.     }
  60.     puts(result);
  61.  
  62.  
  63.     //считывание2
  64.    
  65.     printf("Введите стоку из %d символов:\n", ChLength1);
  66.     for (i=0;i < ChLength1 && ch1[i-1] != '\n'; i++){
  67.         ch1[i] = getchar();
  68.     }
  69.     ch1[i-1]='\0';
  70.     //парсинг строки2
  71.     pch1[0] = strtok (ch1," ");
  72.     for (int i = 1; pch1[i-1] != NULL; i++){
  73.         pch1[i] = strtok (NULL, " ");
  74.     }
  75.  
  76.     //реальная длина массива2
  77.     int end1 = 0;
  78.     while(pch1[end1++] != '\0') { }
  79.     end1-=2;
  80.    
  81.     //сортировка2
  82.     printf("по убыванию: \n");
  83.     for(int i = 0; i < end1; i++){
  84.         for(int j = end1; j> i; j--){
  85.             if (*pch1[i] < *pch1[j])
  86.             {
  87.                 char *temp1 = pch1[i];
  88.                 pch1[i] = pch1[j];
  89.                 pch1[j] = temp1;
  90.             }
  91.         }
  92.     }
  93.     //сложение строк2
  94.     strcpy(result1,pch1[0]);
  95.     for (int i = 1; i <= end1; i++){
  96.         strcat(result1, " ");
  97.         strcat(result1, pch1[i]);
  98.     }
  99.     puts(result1);
  100.  
  101.  
  102.  
  103.  
  104. // итог
  105. //  //result = strtok (ch," ");
  106.     //for (int i = 1; pch[i-1] != NULL; i++){
  107.     //pch[i] = strtok (NULL, " ");
  108.     //}
  109.    strcat(result,result1);
  110.    strcat(itog,result);
  111.  
  112.     puts(itog);
  113.  
  114.  
  115.  
  116.    
  117.     getchar();
  118.     return 0;
  119. }
Add Comment
Please, Sign In to add comment