fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. void addUniqueSeq(char pairSeq[][3], char text[], int i, int &totalSeq) {
  6. int currentPos = 0;
  7. char currentSeq[] = {text[i - 1], text[i], 0};
  8. while (pairSeq[currentPos][0] && strstr(pairSeq[currentPos], currentSeq) == 0) {
  9. ++currentPos;
  10. }
  11. if (pairSeq[currentPos][0] == 0) {
  12. ++totalSeq;
  13. }
  14. strcpy(pairSeq[currentPos], currentSeq);
  15. }
  16.  
  17. int displayNoSeq(char text[]) {
  18. const int MAX_SIZE = 1000;
  19. char pairSeq[MAX_SIZE + 1][3] = {0};
  20. int totalSeq = 0;
  21. for (int i = 1; text[i]; ++i) {
  22. addUniqueSeq(pairSeq, text, i, totalSeq);
  23. }
  24. return totalSeq;
  25. }
  26.  
  27. int main() {
  28. char text[] = "ababb";
  29. cout << displayNoSeq(text);
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
3