Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <ctype.h>
- #include <math.h>
- #include <string.h>
- #define EPS 1e-8
- #define pi 3.1415926535897932384626433832795028841971693993751
- #define N 2147483647
- /*freopen("sample.txt", "r", stdin);*/
- #define NUMBER_STRINGS 50010 /* Number of strings */
- #define STRING_SIZE 500 /* Size of string */
- #define START_SUBSTRING 0 /* Start of of subscript in string to compare */
- #define LENGTH_SUBSTRING dd /* Length of substring to compare (size of largest string) */
- static int str_start, len;
- char str2[NUMBER_STRINGS][STRING_SIZE];
- char str[NUMBER_STRINGS][STRING_SIZE];
- static int cmp( const void *, const void * );
- void sort_str( void *s, int num_elements, int str_size, int start, int length );
- static int cmp( const void *a, const void *b )
- {
- return strncmp( ( ( char * ) a ) + str_start,
- ( ( char * ) b ) + str_start, len );
- }
- void sort_str( void *s, int num_elements, int str_size, int start, int length )
- {
- str_start = start;
- len = length;
- qsort( s, num_elements, str_size, cmp );
- }
- int main()
- {
- int i, j, l, len2, dd, ff, z, n, k;
- dd = 0, i = 0;
- /*freopen("sample.txt", "r", stdin);*/
- for (i = 0; ;i++)
- {
- gets(str[i]);
- if (feof(stdin)) break;
- }
- l = 0, n = i;
- for (k = 0; k < n; k++)
- {
- if (str[k][0] == '\0') continue;
- for (j = 0; str[k][j] != '\0'; j++)
- {
- if (isalpha(str[k][j]) || (str[k][j] == '-' && str[k][j + 1] != '\0'))
- {
- if (isupper(str[k][j])) str[k][j] = tolower(str[k][j]);
- str2[i][l] = str[k][j];
- l++;
- }
- else
- {
- if (str[k][j] == '-' && str[k + 1][0] != '\0' && str[k][j + 1] == '\0') {}
- else
- {
- str2[i][l] = '\0';
- len2 = strlen(str2[i]);
- if (len2 > dd) dd = len2;
- i++;
- l = 0;
- }
- }
- }
- if (str[k][j - 1] == '-' && str[k + 1][0] != '\0') {}
- else
- {
- str2[i][l] = '\0';
- len2 = strlen(str2[i]);
- if (len2 > dd) dd = len2;
- i++;
- l = 0;
- }
- }
- ff = i;
- sort_str (str2, ff, STRING_SIZE, START_SUBSTRING, LENGTH_SUBSTRING);
- z = 0;
- for (j = 0; j < i; j++)
- {
- if (str2[j][0] == '\0') continue;
- if (j != 0)
- {
- z = strcmp(str2[j - 1], str2[j]);
- }
- if (z != 0) printf("%s\n", str2[j]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement