Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- void ordena_bolha(char v[], int n)
- {
- int i,j;
- for (i = 0; i < n; i++)
- {
- // encontra o menor elemento
- for (j = 1; j < n-i; j++)
- if (v[j-1] > v[j])
- {
- // faz a troca de posicoes entre o menor e a posicao i. (copiando estruturas).
- troca(&v[j-1],&v[j]);
- // ou pode fazer sem chamar a funcao.
- //temp = v[j-1];
- //v[j-1] = v[j];
- //v[j] = temp;
- }
- }
- }
- void troca(char *a,char *b)
- {
- char p = *a;
- *a = *b;
- *b = p;
- }
- int main()
- {
- char frase[80],frase2[80];
- int cont,i,j,soma=0;
- char *p,*c;
- gets(frase);
- cont = strlen (frase);
- strcpy(frase2,frase);
- ordena_bolha(frase,cont);
- for(i=0;i<cont;i++)
- {
- soma = 0;
- p = &frase[i];
- for(j=0;j<cont;j++)
- {
- c = &frase[j];
- if(*p == *c)
- {
- soma++;
- if((soma > 1) && (i != j) && (*p == *c))
- *c = '0';
- }
- }
- if(frase[i] != '0' && frase[i] != ' ')
- printf("%c %d\n",frase[i],soma);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment