B-A Reverse AtCoder Beginner Contest 233
Approach-
Do l-- and r-- for 0 based indexing, then firstly print character at index less than l. After this make a new string of characters from l index to r index inclusive. Print the reverse of this string. Then print remaining characters from r+1 to n-1, where n is length of original string.
Code-
long long l, r;
cin>>l>>r;
l--;
r--;
string s;
cin>>s;
long long n=s.length();
for(long long i=0;i<l;i++)
cout<<s[i];
string temp="";
for(long long i=l;i<=r;i++)
temp+=s[i];
reverse(temp.begin(), temp.end());
cout<<temp;
for(long long i=r+1;i<n;i++)
cout<<s[i];
Other Problems from this Contest-
Disclaimer- Everything is published after the actual contest gets over.
Comments
Post a Comment