fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int LongestConsecutiveCharacter(const std::string& s) {
  6. // Write your logic here.
  7. // Parameters:
  8. // s (const std::string&): The passcode string consisting of lowercase alphabets
  9. // Returns:
  10. // int: Length of the longest part of the passcode that contains only one unique character
  11. int n = s.length();
  12. if (n==1) return 1;
  13. int maxi = INT_MIN;
  14. for (int i=0;i<n-1;i++) {
  15. int cnt = 1;
  16. while (s[i] == s[i+1]) {
  17. cnt++;
  18. if (cnt > maxi) {
  19. maxi = cnt;
  20. }
  21. i++;
  22. }
  23. }
  24. return maxi;
  25. }
  26.  
  27. int main() {
  28. std::string s;
  29. std::getline(std::cin, s);
  30. cout << s << "fds";
  31.  
  32. // Call user logic function and print the output
  33. int result = LongestConsecutiveCharacter(s);
  34. std::cout << result << std::endl;
  35.  
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0.01s 5288KB
stdin
p\r\n
stdout
p\r\nfds-2147483648