Hamming Distance Discussions | Algorithms | HackerRank
  • + 0 comments

    include

    include

    include

    include

    include

    include

    include

    using namespace std; string func(char ch,string s) { if(ch=='C') { int l,r; cin>>l>>r; char ch; cin>>ch; for(int i=l-1;i>l1>>r1>>l2>>r2; s1=s1+s.substr(l1-1,r1-l1+1); s2=s2+s.substr(l2-1,r2-l2+1); string s3=s.substr(0,l1-1); string s4=s.substr(r2-1,s.size()-r2); string s5=s.substr(r1,l2-r1-1); s=s3+s2+s5+s1+s4; cout<

    }
    else if(ch=='R')
    {
        int l,r;
        cin>>l>>r;
        reverse(s.begin()+l-1,s.begin()+r);
        cout<<s<<endl;
    }
    else if(ch=='W')
    {
        int l1,r1;
        cin>>l1>>r1;
        string s1=s.substr(l1-1,r1-l1+1);
        cout<<s1<<endl;
        cout<<s<<endl;
    }
    else if(ch=='H')
    {
        int count=0;
        int l1,l2,l;
        cin>>l1>>l2>>l;
        string s1=s.substr(l1-1,l);
        string s2=s.substr(l2-1,l);
        for(int i=0;i<s1.size();i++)
        {
            if(s1[i]!=s2[i])
            count++;
        }
        cout<<count<<endl;
        cout<<s<<endl;
    }
    return s;
    

    }

    int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int n; string s; cin>>n>>s; int m; cin>>m; for(int i=0;i>c; s=func(c,s); }} CAN ANYONE TELL WHERE I AM WRONG I HAVE PRINTED COUT IN EACH CASE JUT TO CHECK WHAT HAPPENS IN EVERYCASE } return 0; }