Codeforces Round #658 (Div. 2) 1382C1. Prefix Flip (Easy Version) Solution




Problem Link :  https://codeforces.com/contest/1382/problem/C1 

 Solution in C++:

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long  t,n,i;
    cin>>t;
    while(t--)
    {
        cin>>n;
        string a,b;
        vector<int>v;
        cin>>a>>b;
        if(a[0]!=b[0])
            v.push_back(1);
        for(i=1; i<n; i++)
        {
            if(a[i]!=b[i])
            {
                v.push_back(i+1);
                v.push_back(1);
                v.push_back(i+1);
            }
        }
        cout<<v.size()<<" ";
        for(i=0;i<v.size();i++)
        {
            cout<<v[i]<<" ";
        }
        cout<<endl;
    }
}
 



 


No comments

Most View Post

Recent post

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.