Codeforces Round 747 (Div. 2) 1594C - Make Them Equal Solution


 

Problem Link :  https://codeforces.com/contest/1594/problem/C

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;
  8. cin >> t;
  9. while (t--) {
  10. int n;
  11. char c;
  12. cin >> n >> c;
  13. string s;
  14. cin >> s;
  15. int cnt = 0 ;
  16. for ( int i = 0 ; i < n ; i++) {
  17. cnt += (s[i] == c ) ;
  18. }
  19. if (cnt == n ){
  20. cout <<"0\n" ;
  21. continue ;
  22. }
  23. bool ok = false ;
  24. for ( int i = 1 ; i <= n ; i++) {
  25. cnt = 0 ;
  26. for ( int j = i ; j <= n ; j += i ){
  27. cnt += (s[j-1]!= c ) ;
  28. }
  29. if ( cnt == 0 ){
  30. cout <<"1\n";
  31. cout << i <<'\n' ;
  32. ok = true ;
  33. break ;
  34. }
  35. }
  36. if (!ok){
  37. cout <<"2\n";
  38. cout << n-1<<" "<<n<<'\n' ;
  39. }
  40. }
  41. return 0;
  42. }

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.