1085A - Right-Left Cipher - CodeForces Solution


implementation strings *800

Please click on ads to support us..

Python Code:

s = input()
n = len(s)
st = ""
l = 0
r = n - 1
if(n % 2 == 0): 
    while(l <= r):
        st = s[r] + st
        r -= 1
        if(l <= r):
            st = s[l] + st
            l += 1
else:
    while(l <= r):
        st = s[l] + st
        l += 1
        if(l <= r):
            st = s[r]+ st
            r -= 1
print(st)

C++ Code:

#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
//int n;cin>>n;

        string s;cin>>s;
       int start=0;int end=s.length()-1;
       string p="";
int l=s.length();
while(start<=end){
        if(start==end){
    p=s[end]+p;break;
        }
    if(start!=end&&!(l&1)){
    p=s[end]+p;
    p=s[start]+p;}
    else{
    p=s[start]+p;
    p=s[end]+p;

    }
    end--;start++;

}

     cout<<p<<endl;

        return 0;}


Comments

Submit
1 Comments
  • 27/10/2023 20:57 - Europe/Dublin

mr ilvr eihthetddeeWhr i h ichkrtae nfo?


More Questions

1140D - Minimum Triangulation
75C - Modified GCD
1722A - Spell Check
1722B - Colourblindness
1722D - Line
1722C - Word Game
1722G - Even-Odd XOR
552E - Vanya and Brackets
933A - A Twisty Movement
1722F - L-shapes
1196B - Odd Sum Segments
1325D - Ehab the Xorcist
552B - Vanya and Books
1722E - Counting Rectangles
168A - Wizards and Demonstration
168B - Wizards and Minimal Spell
7A - Kalevitch and Chess
912B - New Year's Eve
1537C - Challenging Cliffs
879B - Table Tennis
1674E - Breaking the Wall
1282A - Temporarily unavailable
1366C - Palindromic Paths
336A - Vasily the Bear and Triangle
926A - 2-3-numbers
276D - Little Girl and Maximum XOR
1253C - Sweets Eating
1047A - Little C Loves 3 I
758D - Ability To Convert
733A - Grasshopper And the String