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