Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. int compare (const void * a, const void * b)
  7. {
  8.   return ( *(char*)a - *(char*)b );
  9. }
  10.  
  11. int main()
  12. {
  13.     while(1)
  14.     {
  15.          
  16.         if(feof(stdin))
  17.         break;
  18.          
  19.         char string[51];
  20.          
  21.          
  22.         int n = 0 ;
  23.          
  24.         while(1)
  25.         {
  26.             string[n] = getchar();
  27.             if (feof(stdin)) break;
  28.             if(string[n] == '\n')break;
  29.             if(string[n] != ' ') n++;
  30.         }
  31.         if(feof(stdin))
  32.         break;
  33.          
  34.         string[n] = '\0';
  35.         if(n==0)
  36.         {
  37.             printf("\n");
  38.             continue;
  39.         }
  40.         qsort(string, n, sizeof(char), compare);
  41.          
  42.          
  43.         //printf("%s\n",string);
  44.          
  45.         int aux=0;
  46.         int inicio =0;
  47.         int i;
  48.         for(i = 1; i < n; i++)
  49.         {
  50.             if(string[i] == string[i-1] +1 || string[i] == string[i-1])
  51.             {
  52.                 aux++;
  53.             }
  54.             else
  55.             {
  56.                 printf("%c:%c, ", string[inicio], string[inicio+aux]);
  57.                 aux =0;
  58.                 inicio=i;
  59.             }
  60.              
  61.         }
  62.         printf("%c:%c\n", string[inicio], string[inicio+aux]);
  63.          
  64.          
  65.     }
  66.      
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement