Advertisement
AmidamaruZXC

Untitled

Jun 8th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <Windows.h>
  4. #include <stdlib.h>
  5. #include <malloc.h>
  6. #include <string.h>
  7. #include <locale.h>
  8.  
  9. int main()
  10. {
  11.     SetConsoleCP(1251);
  12.     SetConsoleOutputCP(1251);
  13.     int i = 0;
  14.     char c;
  15.     int* a;
  16.     a = (int*)malloc(sizeof(int));
  17.     a[0] = 0;
  18.     int n = 0;
  19.     char s[60] = "";
  20.     while ((c = getchar()) != '.' && i <= 60 && c != '\n')
  21.     {
  22.         if (c != ' ')
  23.         {
  24.             s[i] = c;
  25.             i++;
  26.         }
  27.         else
  28.         {
  29.             int flag = 0;
  30.             for (int j = 0; j < n; j++)
  31.             {
  32.                 if (a[j] == i) flag = 1;
  33.             }
  34.             if (flag == 0)
  35.             {
  36.                 a = (int*)realloc(a, sizeof(a) + sizeof(int));
  37.                 a[n] = i;
  38.                 n++;
  39.             }
  40.         }
  41.     }
  42.     a = (int*)realloc(a, sizeof(a) + sizeof(int));
  43.     a[n] = i;
  44.     printf("\nYour line: %s", s);
  45.     printf("\n");
  46.     for (int i = 0; i <= n; i++) printf("%d\t", a[i]);
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement