Codeforces Round 747 (Div. 2) 1594C - Make Them Equal Solution
Problem Link : https://codeforces.com/contest/1594/problem/C
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n;
- char c;
- cin >> n >> c;
- string s;
- cin >> s;
- int cnt = 0 ;
- for ( int i = 0 ; i < n ; i++) {
- cnt += (s[i] == c ) ;
- }
- if (cnt == n ){
- cout <<"0\n" ;
- continue ;
- }
- bool ok = false ;
- for ( int i = 1 ; i <= n ; i++) {
- cnt = 0 ;
- for ( int j = i ; j <= n ; j += i ){
- cnt += (s[j-1]!= c ) ;
- }
- if ( cnt == 0 ){
- cout <<"1\n";
- cout << i <<'\n' ;
- ok = true ;
- break ;
- }
- }
- if (!ok){
- cout <<"2\n";
- cout << n-1<<" "<<n<<'\n' ;
- }
- }
- return 0;
- }
No comments