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. } else {
  19. string temp = "" + c;
  20. if (temp == tmp) {
  21. cout <<"char " << temp << " matches with" << tmp << endl;
  22. streak++;
  23. maxstreak = max(streak, maxstreak);
  24. } else {
  25. streak = 1;
  26. }
  27.  
  28. }
  29. }
  30. cout << maxstreak;
  31. }
Success #stdin #stdout 0.01s 5268KB
stdin
ATTCGGGA
stdout
current char: A
current temp: 
current streak and max 00
current char: T
current temp: A
current streak and max 00
current char: T
current temp: A
current streak and max 10
current char: C
current temp: A
current streak and max 10
current char: G
current temp: A
current streak and max 10
current char: G
current temp: A
current streak and max 10
current char: G
current temp: A
current streak and max 10
current char: A
current temp: A
current streak and max 10
0