Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define NUMBER_OF_STRINGS 3
  5. #define STRING_MAX_LEN 32
  6.  
  7.  
  8. int main(void) {
  9.     ///
  10.     char a[NUMBER_OF_STRINGS][STRING_MAX_LEN];
  11.     char b[NUMBER_OF_STRINGS][STRING_MAX_LEN];
  12.     char c[NUMBER_OF_STRINGS * 2][STRING_MAX_LEN];
  13.     char str[32];
  14.     ///
  15.     printf("input a of 3 strings (Enter - finish)\n");
  16.     ///
  17.     for (int i = 0; i < NUMBER_OF_STRINGS; i++) {
  18.         scanf("%s", a[i]);
  19.     }
  20.     ///
  21.     printf("input b of 3 strings (Enter - finish)\n");
  22.     for (int i = 0; i < NUMBER_OF_STRINGS; i++) {
  23.         scanf("%s", b[i]);
  24.     }
  25.     ///
  26.     printf("%i, a: ", NUMBER_OF_STRINGS);
  27.     for (int i = 0; i < NUMBER_OF_STRINGS; i++) {
  28.         printf("%s%c", a[i], i == NUMBER_OF_STRINGS - 1 ? '\n' : ' ');
  29.     }
  30.     ///
  31.     printf("b: ");
  32.     for (int i = 0; i < NUMBER_OF_STRINGS; i++) {
  33.         printf("%s%c", b[i], i == NUMBER_OF_STRINGS - 1 ? '\n' : ' ');
  34.     }
  35.  
  36.     for (int i = 0; i < NUMBER_OF_STRINGS * 2; i++) {
  37.         strcpy(c[i], (i >= 3) ? b[i - NUMBER_OF_STRINGS] : a[i]);
  38.     }
  39.  
  40.  
  41.  
  42.     for (int i = 0; i < NUMBER_OF_STRINGS * 2; i++) {
  43.         for (int j = 0; j < NUMBER_OF_STRINGS * 2; j++) {
  44.             if (c[i][0] < c[j][0]) {
  45.                 strcpy(str, c[i]);
  46.                 strcpy(c[i], c[j]);
  47.                 strcpy(c[j], str);
  48.             }
  49.         }
  50.     }
  51.  
  52.     for (int i = 0; i < NUMBER_OF_STRINGS * 2; i++) {
  53.         printf("%s\n", c[i]);
  54.     }
  55.    
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement