Advertisement
palmerstone

Untitled

Jul 16th, 2011
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <math.h>
  5. #include <string.h>
  6. #define EPS 1e-8
  7. #define pi 3.1415926535897932384626433832795028841971693993751
  8. #define N 2147483647
  9. /*freopen("sample.txt", "r", stdin);*/
  10.  
  11. #define NUMBER_STRINGS 50010 /* Number of strings */
  12. #define STRING_SIZE 500 /* Size of string */
  13. #define START_SUBSTRING 0 /* Start of of subscript in string to compare */
  14. #define LENGTH_SUBSTRING dd /* Length of substring to compare (size of largest string) */
  15.  
  16. static int str_start, len;
  17. char str2[NUMBER_STRINGS][STRING_SIZE];
  18. char str[NUMBER_STRINGS][STRING_SIZE];
  19.  
  20. static int cmp( const void *, const void * );
  21. void sort_str( void *s, int num_elements, int str_size, int start, int length );
  22.  
  23. static int cmp( const void *a, const void *b )
  24. {
  25. return strncmp( ( ( char * ) a ) + str_start,
  26. ( ( char * ) b ) + str_start, len );
  27. }
  28.  
  29. void sort_str( void *s, int num_elements, int str_size, int start, int length )
  30. {
  31. str_start = start;
  32. len = length;
  33. qsort( s, num_elements, str_size, cmp );
  34. }
  35.  
  36. int main()
  37. {
  38. int i, j, l, len2, dd, ff, z, n, k;
  39. dd = 0, i = 0;
  40. /*freopen("sample.txt", "r", stdin);*/
  41. for (i = 0; ;i++)
  42. {
  43. gets(str[i]);
  44. if (feof(stdin)) break;
  45.  
  46. }
  47.  
  48. l = 0, n = i;
  49. for (k = 0; k < n; k++)
  50. {
  51. if (str[k][0] == '\0') continue;
  52. for (j = 0; str[k][j] != '\0'; j++)
  53. {
  54. if (isalpha(str[k][j]) || (str[k][j] == '-' && str[k][j + 1] != '\0'))
  55. {
  56. if (isupper(str[k][j])) str[k][j] = tolower(str[k][j]);
  57. str2[i][l] = str[k][j];
  58. l++;
  59. }
  60. else
  61. {
  62. if (str[k][j] == '-' && str[k + 1][0] != '\0' && str[k][j + 1] == '\0') {}
  63. else
  64. {
  65. str2[i][l] = '\0';
  66. len2 = strlen(str2[i]);
  67. if (len2 > dd) dd = len2;
  68. i++;
  69. l = 0;
  70. }
  71. }
  72. }
  73. if (str[k][j - 1] == '-' && str[k + 1][0] != '\0') {}
  74. else
  75. {
  76. str2[i][l] = '\0';
  77. len2 = strlen(str2[i]);
  78. if (len2 > dd) dd = len2;
  79. i++;
  80. l = 0;
  81. }
  82. }
  83.  
  84. ff = i;
  85. sort_str (str2, ff, STRING_SIZE, START_SUBSTRING, LENGTH_SUBSTRING);
  86. z = 0;
  87. for (j = 0; j < i; j++)
  88. {
  89. if (str2[j][0] == '\0') continue;
  90. if (j != 0)
  91. {
  92. z = strcmp(str2[j - 1], str2[j]);
  93. }
  94. if (z != 0) printf("%s\n", str2[j]);
  95. }
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement