Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. /* Dasprog C - 2019
  2. William Handi Wijaya
  3. 0087
  4.  
  5. Program untuk menghitung banyak kata "Martin"
  6. yang dapat dibentuk dari string input.
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11.  
  12. char input[1005];
  13. int len, test, banyak, j, i;
  14. char cek[] = {'M', 'A', 'R', 'T', 'I', 'N'};
  15. void detectMartin();
  16.  
  17. int main()
  18. {
  19.     // Input testcase
  20.     scanf("%d", &test);
  21.     getchar();
  22.    
  23.     // For testcase
  24.     for (int t = 0; t < test; t++)
  25.     {
  26.         banyak = j = 0;
  27.         // Get string input
  28.         gets(input);
  29.         len = strlen(input);
  30.         detectMartin();
  31.        
  32.         printf("%d\n", banyak);
  33.     }
  34.     return 0;
  35. }
  36.  
  37. void detectMartin()
  38. {
  39.     // For every word
  40.     for (i = 0; i < len; i++)
  41.     {
  42.         // If word == salah satu huruf "MARTIN" pada index ke j
  43.         if (input[i] == cek[j])
  44.         {
  45.             input[i] = 0;
  46.             // Increment index MARTIN
  47.             j++;
  48.         }
  49.         // Jika terbentuk kata "MARTIN"
  50.         if (j == 6)
  51.         {
  52.             banyak++;
  53.             j = i = 0;
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement