fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long iint;
  4.  
  5. int main() {
  6. string s;
  7. cin >> s;
  8. string tmp = "";
  9. int streak = 0;
  10. int maxstreak = 0;
  11. // ATTCG
  12. for (char c : s) {
  13. cout << "current char: " << c << endl;
  14. cout << "current temp: " << tmp << endl;
  15. if (tmp == "") {
  16. tmp += c;
  17. streak++;
  18. cout << "current streak and max " << streak << " " << maxstreak << endl;
  19. } else {
  20. string temp = "" + c;
  21. if (temp == tmp) {
  22. cout <<"char " << temp << " matches with" << tmp << endl;
  23. streak++;
  24. maxstreak = max(streak, maxstreak);
  25. cout << "current streak and max " << streak << " " << maxstreak << endl;
  26. } else {
  27. streak = 1;
  28. cout << "current streak and max " << streak << " " << maxstreak << endl;
  29. tmp = temp;
  30. }
  31.  
  32. }
  33. }
  34. cout << maxstreak;
  35. }
Success #stdin #stdout 0.01s 5332KB
stdin
ATTCGGGA
stdout
current char: A
current temp: 
current streak and max 1 0
current char: T
current temp: A
current streak and max 1 0
current char: T
current temp: �L
char �L matches with�L
current streak and max 2 2
current char: C
current temp: �L
current streak and max 1 2
current char: G
current temp: ���
current streak and max 1 2
current char: G
current temp: �
char � matches with�
current streak and max 2 2
current char: G
current temp: �
char � matches with�
current streak and max 3 3
current char: A
current temp: �
current streak and max 1 3
3