Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <string.h>
- #include <stdbool.h>
- #define LIM_TXT 20000
- char texto[LIM_TXT];
- int comecoPalavra = 0, fimPalavra = 0, achouPalavra;
- bool eLetra(char letra);
- bool eCaractereConsideravel(char caractere);
- void embaralha();
- void achaPalavra(int comeco);
- int main()
- {
- srand(time(NULL));
- int i;
- printf("Digite o texto:\n");
- fflush(stdin);
- gets(texto);
- embaralha();
- puts(texto);
- getch();
- }
- bool eLetra(char letra)
- {
- if( ( (int)letra >= 65 && (int)letra <= 90) || ( (int)letra >= 97 && (int)letra <= 122))
- return true;
- else
- return false;
- }
- void embaralha()
- {
- int i, tlPosicoes, posicoes[LIM_TXT], pos1, pos2;
- char aux;
- i = 0;
- while(i <= strlen(texto))
- {
- achaPalavra(i);
- if(achouPalavra == 1)
- {
- if(fimPalavra - comecoPalavra > 2)
- {
- tlPosicoes = 0;
- for(i = comecoPalavra + 1; i <= fimPalavra - 1; i++)
- {
- posicoes[tlPosicoes] = i;
- tlPosicoes++;
- }
- while(tlPosicoes > 1)
- {
- do
- {
- pos1 = rand() % tlPosicoes;
- pos2 = rand() % tlPosicoes;
- }while(pos1 == pos2);
- aux = texto[posicoes[pos1]];
- texto[posicoes[pos1]] = texto[posicoes[pos2]];
- texto[posicoes[pos2]] = aux;
- for(i = pos1; i < tlPosicoes; i++)
- posicoes[i] = posicoes[i + 1];
- tlPosicoes--;
- for(i = pos2; i < tlPosicoes; i++)
- posicoes[i] = posicoes[i + 1];
- tlPosicoes--;
- }
- }
- i = fimPalavra + 2;
- }
- else
- i++;
- }
- }
- void achaPalavra(int comeco)
- {
- int i, j;
- achouPalavra = 0;
- for(i = comeco; achouPalavra == 0 && i <= strlen(texto); i++)
- {
- if((texto[i] == ' ' || texto[i] == '\0' || texto[i] == 10 || eCaractereConsideravel(texto[i])) && toupper(texto[i - 1]) >= 'A' && toupper(texto[i - 1]) <= 'Z')
- {
- fimPalavra = i - 1;
- for(j = i - 1; eLetra(texto[j - 1]); j--)
- comecoPalavra = j;
- comecoPalavra = j;
- achouPalavra = 1;
- }
- }
- }
- bool eCaractereConsideravel(char caractere)
- {
- if((caractere >= 33 && caractere <= 64) || (caractere >= 91 && caractere <= 96) || (caractere >= 123 && caractere <= 126))
- return true;
- else
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement