Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #include <stdlib.h>
- int compare (const void * a, const void * b)
- {
- return ( *(char*)a - *(char*)b );
- }
- int main()
- {
- while(1)
- {
- if(feof(stdin))
- break;
- char string[51];
- int n = 0 ;
- while(1)
- {
- string[n] = getchar();
- if (feof(stdin)) break;
- if(string[n] == '\n')break;
- if(string[n] != ' ') n++;
- }
- if(feof(stdin))
- break;
- string[n] = '\0';
- if(n==0)
- {
- printf("\n");
- continue;
- }
- qsort(string, n, sizeof(char), compare);
- //printf("%s\n",string);
- int aux=0;
- int inicio =0;
- int i;
- for(i = 1; i < n; i++)
- {
- if(string[i] == string[i-1] +1 || string[i] == string[i-1])
- {
- aux++;
- }
- else
- {
- printf("%c:%c, ", string[inicio], string[inicio+aux]);
- aux =0;
- inicio=i;
- }
- }
- printf("%c:%c\n", string[inicio], string[inicio+aux]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement