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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

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

Powered by Blogger.