Educational Codeforces Round 149 (Rated for Div. 2) 1837B - Comparison String Solution


  

Problem Link : https://codeforces.com/problemset/problem/1837/B

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t; cin >> t;
  8. while (t--) {
  9. int n ;
  10. cin >> n ;
  11. string s ;
  12. cin >> s;
  13. int ans = 0 , cnt = 1 ;
  14. for ( int i = 0 ; i < n ; i++) {
  15. if (s[i] == s[i+1]) cnt++ ;
  16. else {
  17. ans = max(ans,cnt);
  18. cnt = 1 ;
  19. }
  20. }
  21. cout << ans + 1 << '\n';
  22. }
  23. return 0 ;
  24. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.