Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define MAX_TEXTOS 25
- #define MAX_PALAVRAS 25
- #define MAX_COMPRIMENTO_PALAVRA 25
- int main() {
- int textos;
- printf("Digite o número de textos: ");
- scanf("%d", &textos);
- getchar(); // Consume the newline character left in the input buffer
- char entrada[MAX_TEXTOS][MAX_PALAVRAS][MAX_COMPRIMENTO_PALAVRA];
- char texto[MAX_TEXTOS][MAX_PALAVRAS * MAX_COMPRIMENTO_PALAVRA];
- int contPalavras[MAX_TEXTOS] = {0};
- for(int i = 0; i < textos; i++) {
- printf("Digite o texto %d: ", i + 1);
- fgets(texto[i], sizeof(texto[i]), stdin);
- // Removing the trailing newline character from the input
- if (texto[i][strlen(texto[i]) - 1] == '\n') {
- texto[i][strlen(texto[i]) - 1] = '\0';
- }
- }
- // Separando o texto em palavras distintas
- for(int i = 0; i < textos; i++) {
- int index = 0;
- for (int j = 0; j <= strlen(texto[i]); j++) {
- if (texto[i][j] == ' ' || texto[i][j] == '\0') {
- entrada[i][contPalavras[i]][index] = '\0';
- contPalavras[i]++;
- index = 0;
- } else {
- entrada[i][contPalavras[i]][index] = texto[i][j];
- index++;
- }
- if (contPalavras[i] == MAX_PALAVRAS)
- break;
- }
- }
- // Imprimindo as palavras separadas
- printf("Palavras separadas:\n");
- for(int i = 0; i < textos; i++) {
- printf("Texto %d:\n", i + 1);
- for (int j = 0; j < contPalavras[i]; j++) {
- printf("%s\n", entrada[i][j]);
- }
- printf("\n");
- }
- char destaques[25][MAX_COMPRIMENTO_PALAVRA];
- int numDestaques;
- printf("Digite quantos destaques você quer: ");
- scanf("%d", &numDestaques);
- getchar(); // Consume the newline character left in the input buffer
- printf("Digite as palavras a serem destacadas:\n");
- for(int i = 0 ; i < numDestaques ; i++){
- printf("Destaque %d: ", i + 1);
- scanf("%s", destaques[i]);
- }
- int posicoes[25][25];
- int numPosicoes[25] = {0};
- // Searching for destaques in entrada matrix and storing the positions
- for(int i = 0 ; i < textos ; i++){
- for(int j = 0 ; j < contPalavras[i] ; j++){
- for(int k = 0 ; k < numDestaques ; k++){
- if(strcmp(entrada[i][j], destaques[k]) == 0){
- posicoes[i][numPosicoes[i]] = j;
- numPosicoes[i]++;
- }
- }
- }
- }
- // Printing
- // Printing the positions matrix
- printf("\nPosições:\n");
- for (int i = 0; i < textos; i++) {
- printf("Texto %d:\n", i + 1);
- for (int j = 0; j < numPosicoes[i]; j++) {
- printf("%d ", posicoes[i][j]);
- }
- printf("\n");
- }
- return(0);
- }
Add Comment
Please, Sign In to add comment