minilose

Untitled

Jan 26th, 2022 (edited)
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.16 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. char buff1[61];
  4. char buff2[61];
  5. void modify(char* ptr)
  6. {
  7.     while (*(ptr + 1) != *ptr && *(ptr + 1) != '\0')
  8.     {
  9.         *(ptr + 1) = *ptr;
  10.         ptr++;
  11.     }
  12. }
  13. void better_modify(char* ptr)
  14. {
  15.     char first = ptr[0];
  16.     while (*ptr != '\0' && *(ptr + 1) != '\0')
  17.     {
  18.         while (*ptr == first)
  19.         {
  20.             ptr++;
  21.         }
  22.         while (*ptr != first && *(ptr + 1) != '\0')
  23.         {
  24.             ptr++;
  25.         }
  26.         modify(ptr);
  27.     }
  28. }
  29. int input(int index)
  30. {
  31.     printf("\n\n==== INPUT ====\n\n");
  32.     if (index == 1)
  33.     {
  34.         gets_s(buff1, 61);
  35.         if (buff1[0] == '\0')
  36.         {
  37.             return 3;
  38.         }
  39.         return 1;
  40.     }
  41.     if (index == 2)
  42.     {
  43.         gets_s(buff2, 61);
  44.         if (buff2[0] == '\0')
  45.         {
  46.             return 3;
  47.         }
  48.         return 2;
  49.     }
  50. }
  51. int output(int index)
  52. {
  53.     printf("\n\n==== OUTPUT ====\n\n");
  54.     if (index == 1)
  55.     {
  56.         puts(buff1);
  57.         return 2;
  58.     }
  59.     if (index == 2)
  60.     {
  61.         puts(buff2);
  62.         return 1;
  63.     }
  64. }
  65. void main()
  66. {
  67.     int check = input(1);
  68.     while (check != 3)
  69.     {
  70.         if(check==1)
  71.         {
  72.             modify(&buff1);
  73.             better_modify(&buff1);
  74.         }
  75.         if(check==2)
  76.         {
  77.             modify(&buff2);
  78.             better_modify(&buff2);
  79.         }
  80.         check = output(check);
  81.         check = input(check);
  82.     }
  83.     system("pause");
  84. }
Add Comment
Please, Sign In to add comment