that_one_nigga_you_k

lista de string 1

Jul 5th, 2023 (edited)
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define MAX_TEXTOS 25
  5. #define MAX_PALAVRAS 25
  6. #define MAX_COMPRIMENTO_PALAVRA 25
  7.  
  8. int main() {
  9.  
  10.     int textos;
  11.  
  12.     printf("Digite o número de textos: ");
  13.     scanf("%d", &textos);
  14.     getchar(); // Consume the newline character left in the input buffer
  15.  
  16.     char entrada[MAX_TEXTOS][MAX_PALAVRAS][MAX_COMPRIMENTO_PALAVRA];
  17.     char texto[MAX_TEXTOS][MAX_PALAVRAS * MAX_COMPRIMENTO_PALAVRA];
  18.     int contPalavras[MAX_TEXTOS] = {0};
  19.  
  20.     for(int i = 0; i < textos; i++) {
  21.         printf("Digite o texto %d: ", i + 1);
  22.         fgets(texto[i], sizeof(texto[i]), stdin);
  23.  
  24.         // Removing the trailing newline character from the input
  25.         if (texto[i][strlen(texto[i]) - 1] == '\n') {
  26.             texto[i][strlen(texto[i]) - 1] = '\0';
  27.         }
  28.     }
  29.  
  30.     // Separando o texto em palavras distintas
  31.     for(int i = 0; i < textos; i++) {
  32.         int index = 0;
  33.         for (int j = 0; j <= strlen(texto[i]); j++) {
  34.             if (texto[i][j] == ' ' || texto[i][j] == '\0') {
  35.                 entrada[i][contPalavras[i]][index] = '\0';
  36.                 contPalavras[i]++;
  37.                 index = 0;
  38.             } else {
  39.                 entrada[i][contPalavras[i]][index] = texto[i][j];
  40.                 index++;
  41.             }
  42.             if (contPalavras[i] == MAX_PALAVRAS)
  43.                 break;
  44.         }
  45.     }
  46.  
  47.     // Imprimindo as palavras separadas
  48.     printf("Palavras separadas:\n");
  49.     for(int i = 0; i < textos; i++) {
  50.         printf("Texto %d:\n", i + 1);
  51.         for (int j = 0; j < contPalavras[i]; j++) {
  52.             printf("%s\n", entrada[i][j]);
  53.         }
  54.         printf("\n");
  55.     }  
  56.    
  57.     char destaques[25][MAX_COMPRIMENTO_PALAVRA];
  58.     int numDestaques;
  59.  
  60.     printf("Digite quantos destaques você quer: ");
  61.     scanf("%d", &numDestaques);
  62.     getchar(); // Consume the newline character left in the input buffer
  63.  
  64.     printf("Digite as palavras a serem destacadas:\n");
  65.     for(int i = 0 ; i < numDestaques ; i++){
  66.         printf("Destaque %d: ", i + 1);
  67.         scanf("%s", destaques[i]);
  68.     }
  69.  
  70.     int posicoes[25][25];
  71.     int numPosicoes[25] = {0};
  72.  
  73.     // Searching for destaques in entrada matrix and storing the positions
  74.     for(int i = 0 ; i < textos ; i++){
  75.         for(int j = 0 ; j < contPalavras[i] ; j++){
  76.             for(int k = 0 ; k < numDestaques ; k++){
  77.                 if(strcmp(entrada[i][j], destaques[k]) == 0){
  78.                     posicoes[i][numPosicoes[i]] = j;
  79.                     numPosicoes[i]++;
  80.                 }
  81.             }
  82.         }
  83.     }
  84.  
  85.     // Printing
  86.     // Printing the positions matrix
  87.     printf("\nPosições:\n");
  88.     for (int i = 0; i < textos; i++) {
  89.         printf("Texto %d:\n", i + 1);
  90.         for (int j = 0; j < numPosicoes[i]; j++) {
  91.             printf("%d ", posicoes[i][j]);
  92.         }
  93.         printf("\n");
  94.     }
  95.    
  96.     return(0);
  97.    
  98. }
Add Comment
Please, Sign In to add comment