Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <cctype>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- struct index
- {
- char str[90];
- int ar2[1000];
- int max;
- };
- struct index ar[5000];
- int compare(const void *a, const void *b)
- {
- char str2[100], str3[100];
- strcpy(str2, ((index *)a)->str);
- strcpy(str3, ((index *)b)->str);
- if (strcmp(str2, str3) > 0) return 1;
- return -1;
- }
- int main()
- {
- int t = 1, i = 0, j, k, l, a, b, c, d, x, y, z, n, no = 0;
- char ch, str2[100], str3[100];
- for (i = 0; i < 5000; i++) ar[i].max = 0;
- //freopen("sample.txt", "r", stdin);
- gets(str2);
- i = 0, ch = str2[0];
- while(gets(str2))
- {
- l = 0;
- for (j = 0; ;j++)
- {
- if (isalpha(str2[j]))
- {
- no = 1;
- str3[l++] = str2[j];
- }
- else if (no == 1)
- {
- no = 0, str3[l] = 0;
- if (str3[0] != ch)
- {
- l = 0;
- continue;
- }
- d = 0;
- for (k = 0; k < i; k++)
- {
- if (strcmp(str3, ar[k].str) == 0)
- {
- d = 1;
- if (ar[k].max == 0) ar[k].ar2[ar[k].max++] = t;
- else if (ar[k].ar2[ar[k].max - 1] != t) ar[k].ar2[ar[k].max++] = t;
- break;
- }
- }
- if (d == 0)
- {
- strcpy(ar[i].str, str3);
- ar[i++].ar2[ar[k].max++] = t;
- }
- l = 0;
- }
- if (str2[j] == 0) break;
- }
- t++;
- }
- qsort(ar, i, sizeof(index), compare);
- for (j = 0; j < i; j++)
- {
- printf("%s", ar[j].str);
- for (k = 0; k < ar[j].max; k++) printf(" %d", ar[j].ar2[k]);
- putchar(10);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement