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. cout << "current streak and max " << streak << " " << maxstreak << endl;
  16. if (tmp == "") {
  17. tmp += c;
  18. streak++;
  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. } else {
  26. streak = 1;
  27. }
  28.  
  29. }
  30. }
  31. cout << maxstreak;
  32. }
Success #stdin #stdout 0.01s 5320KB
stdin
ATTCGGGA
stdout
current char: A
current temp: 
current streak and max 0 0
current char: T
current temp: A
current streak and max 1 0
current char: T
current temp: A
current streak and max 1 0
current char: C
current temp: A
current streak and max 1 0
current char: G
current temp: A
current streak and max 1 0
current char: G
current temp: A
current streak and max 1 0
current char: G
current temp: A
current streak and max 1 0
current char: A
current temp: A
current streak and max 1 0
0