fork download
  1. #include <stdio.h>
  2.  
  3. int countRepeats(char *cptr) {
  4. char prior = *cptr;
  5. int clen = 0;
  6. int result = 0;
  7.  
  8. while(*cptr) {
  9. cptr++;
  10. if (*cptr == prior) {
  11. result += !clen;
  12. clen++;
  13. } else {
  14. prior = *cptr;
  15. clen = 0;
  16. }
  17. }
  18.  
  19. return result;
  20. }
  21.  
  22. void test(int testId, char *text, int expected) {
  23. int actual = countRepeats(text);
  24. if (actual == expected) {
  25. printf("Test %d OK\n", testId);
  26. } else {
  27. printf("Test %d failed, expected: %d, actual: %d\n", testId, expected, actual);
  28. }
  29. }
  30.  
  31. int main(void) {
  32.  
  33. test(1, "Too jeesttt ttest...", 5);
  34. test(2, "", 0);
  35. test(3, "A", 0);
  36. test(4, "AA", 1);
  37. test(5, "AAA", 1);
  38. test(6, "AA A", 1);
  39. test(7, "AA AA", 2);
  40. test(8, " AA", 1);
  41. test(9, "AA ", 1);
  42. test(10, " AA ", 1);
  43. test(11, " A A ", 0);
  44. test(12, "DDBCDCCCCBB", 3);
  45.  
  46. return 0;
  47. }
  48.  
Success #stdin #stdout 0s 5016KB
stdin
Standard input is empty
stdout
Test 1 OK
Test 2 OK
Test 3 OK
Test 4 OK
Test 5 OK
Test 6 OK
Test 7 OK
Test 8 OK
Test 9 OK
Test 10 OK
Test 11 OK
Test 12 OK