[Question]
  [
The goal here is to simply reverse a string, with one twist:  
Keep the capitalization in the same places.
Example Input 1: `Hello, Midnightas`  
Example Output 1: `SathginDim ,olleh` 
Example Input 2: `.Q`  
Exmaple Output 2: `q.` 
**Rules**:
* Output to STDOUT, input from STDIN
* The winner will be picked 13th of July on GMT+3 12:00 (One week)
* The input may only consist of ASCII symbols, making it easier for programs that do not use any encoding that contains non-ASCII characters.
* Any punctuation ending up in a position where there was an upper-case letter must be ignored.
  
[Answer]
## Python, 71 bytes
```
lambda s:''.join((z*2).title()[c.isupper()-1]for c,z in zip(s,s[::-1]))
```
[Try it online](http://ideone.com/fork/py1Kjj)
-3 bytes from Ruud, plus the inspiration for 2 more.
-4 more bytes from FryAmTheEggman
[Answer]
# Python 2, 73 bytes
Since the rules specify the input is ascii:
```
lambda s:''.join([z.lower,z.upper]['@'<c<'[']()for c,z in zip(s,s[::-1]))
```
All the credit goes to @Mego though, but I had not the reputation to just comment on his answer.
[Answer]
## Perl, 31 + 2 (`-lp`) = 33 bytes
*This solution is from [@Ton Hospel](https://codegolf.stackexchange.com/users/51507/ton-hospel) (13 bytes shorter thant mine).*
```
s%.%(lc$&gt$&?u:l)."c chop"%eeg
```
But you'll need `l` and `p` switches on. To run it :
```
perl -lpe 's%.%(lc$&gt$&?u:l)."c chop"%eeg'
```
[Answer]
# Pyth, ~~13~~ ~~11~~ ~~10~~ 9 bytes
*Thanks to @FryAmTheEggman for reminding me about `V` and @LeakyNun for another byte.*
```
srV_Qm!/G
```
[Try it online!](http://pyth.tryitonline.net/#code=c3JWX1F9UnJHMQ&input=IkhlbGxvLCBNaWRuaWdodGFzIg)
now on mobile, updating link in a bit
[Answer]
## Python, 66 bytes
```
f=lambda s,i=0:s[i:]and(s[~i]*2).title()[~('@'<s[i]<'[')]+f(s,i+1)
```
Recurses through the indices `i`, taking the character `s[~i]` from the back and the case of `s[i]` from the front. Being capital is checked as lying in the contiguous range `@ABC...XYZ[`.
Credit to FryAmTheEggman from the `(_*2).title()` trick.
[Answer]
## TCC - 4 bytes
```
<>ci
```
[Try it online!](https://www.ccode.gq/projects/tcc.html?code=%3C%3Eci&input=Hello%2C%20Midnightas)
Explanation:
```
     - output is implicit in TCC
<>   - reverse string
  c  - preserve capitalization
   i - get input
```
[Answer]
## [Retina](https://github.com/m-ender/retina), ~~75~~ ~~67~~ 65 bytes
Byte count assumes ISO 8859-1 encoding.
```
$
±·$`
O$^`\G[^·]
s{T`L`l`±.
T01`l`L`±.*·[A-Z]
±·
±(.)
$1±
·.
·
```
[Try it online!](http://retina.tryitonline.net/#code=JShHYAokCsKxwrckYApPJF5gXEdbXsK3XQoKc3tUYExgbGDCsS4KVDAxYGxgTGDCsS4qwrdbQS1aXQrCscK3CgrCsSguKQokMcKxCsK3LgrCtw&input=SGVsbG8sIE1pZG5pZ2h0YXMKLlEKLnE) (The first line enables a test suite with multiple linefeed-separated test cases.)
[Answer]
## JavaScript (ES6), ~~95~~ 83 bytes
```
s=>[...t=s.toLowerCase()].reverse().map((c,i)=>s[i]==t[i]?c:c.toUpperCase()).join``
```
Edit: Saved a massive 12 bytes thanks to @edc65.
[Answer]
## Pyke, ~~11~~ ~~10~~ 9 bytes
```
_FQo@UhAl
```
[Try it here!](http://pyke.catbus.co.uk/?code=_FQo%40UhAl&input=Hello%2C+Midnightas)
```
_         -   reversed(input)
 F        -  for i in ^
   o      -      o+=1
  Q @     -     input[^]
     Uh   -    ^.is_upper()+1
       Al -   [len, str.lower, str.upper, ...][^](i)
          - "".join(^)
```
[Answer]
# [J](http://jsoftware.com), 30 bytes
```
(={"_1 toupper@]|.@,.])tolower
```
Doesn't support non-ASCII
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), ~~19~~ ~~16~~ ~~15~~ 13 bytes
Thanks to **Emigna** for saving a 3 bytes!
Probably gonna get beat by Jelly... Code:
```
Âuvy¹Nè.lil}?
```
Uses the **CP-1252** encoding. [Try it online!](http://05ab1e.tryitonline.net/#code=w4J1dnnCuU7DqC5saWx9Pw&input=SGVsbG8sIE1pZG5pZ2h0YXM).
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 28 bytes
```
@lr:?z:1ac.
h@u.,@A@um~t?|h.
```
### Explanation
* Main Predicate:
```
@lr                 Reverse the lowercase version of the Input
   :?z              Zip that reversed string with the Input
      :1a           Apply predicate 1 to each couple [char i of reverse, char i of Input]
         c.         Output is the concatenation of the result
```
* Predicate 1:
```
h@u.,               Output is the uppercase version of the first char of Input
     @A@um~t?       The second char of Input is an uppercase letter
             |      Or
              h.    Output is the first char of Input
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 13 bytes
```
PktGtk<)Xk5M(
```
[**Try it online!**](http://matl.tryitonline.net/#code=UGt0R3RrPClYazVNKA&input=J0hlbGxvLCBNaWRuaWdodGFzJw)
```
Pk      % Implicit inpput. Flip, lowercase
t       % Duplicate
Gtk<    % Logical index of uppercase letters in the input string
)       % Get letters at those positions in the flipped string
Xk      % Make them uppercase
5M(     % Assign them to the indicated positions. Implicit display
```
[Answer]
# TSQL, 175 bytes
Golfed:
```
DECLARE @ varchar(99)='Hello, Midnightas'
,@o varchar(99)='',@i INT=0WHILE @i<LEN(@)SELECT
@i+=1,@o+=IIF(ascii(x)=ascii(lower(x)),lower(y),upper(y))FROM(SELECT
SUBSTRING(@,@i+1,1)x,SUBSTRING(@,len(@)-@i,1)y)z
PRINT @o
```
Ungolfed
```
DECLARE @ varchar(99)='Hello, Midnightas'
,@o varchar(99)=''
,@i INT=0
WHILE @i<LEN(@)
  SELECT @i+=1,@o+=IIF(ascii(x)=ascii(lower(x)),lower(y),upper(y))
  FROM
    (SELECT SUBSTRING(@,@i+1,1)x,SUBSTRING(@,len(@)-@i,1)y)z
PRINT @o
```
**[Fiddle](https://data.stackexchange.com/stackoverflow/query/508510/reverse-a-string-while-maintaining-the-capitalization-in-the-same-places)**
[Answer]
## Actually, 25 bytes
```
;`úíuY"ùû"E£`M@ùRZ`i@ƒ`MΣ
```
[Try it online!](http://actually.tryitonline.net/#code=O2DDusOtdVkiw7nDuyJFwqNgTUDDuVJaYGlAxpJgTc6j&input=ImFiQ2Qi)
Explanation:
```
;`úíuY"ùû"E£`M@ùRZ`i@ƒ`MΣ
;                          create a copy of the input
 `úíuY"ùû"E£`M             for each character in input:
  úíuY                       0-based index in lowercase English letters, or -1 if not found, increment, boolean negate (1 if uppercase else 0)
      "ùû"E£                 `û` if the character is lowercase else `ù` (str.lower vs str.upper)
              @ùRZ         make the other copy of the input lowercase, reverse it, and zip it with the map result
                  `i@ƒ`M   for each (string, function) pair:
                   i@ƒ       flatten, swap, apply (apply the function to the string)
                        Σ  concatenate the strings
```
[Answer]
# Haskell, ~~83~~ ~~80~~ ~~75~~ 71 bytes
The most straightforward way I could think of.
```
import Data.Char
f a|isUpper a=toUpper|1>0=toLower
zipWith f<*>reverse
```
[Answer]
# PowerShell, ~~154~~, ~~152~~, ~~99~~, 86 bytes
Thank you @TimmyD for saving me a whopping 47 bytes (I also saved an additional 6)
Thank you @TessellatingHeckler for saving an additional 13 bytes.
Latest:
```
param($a)-join($a[$a.length..0]|%{("$_".ToLower(),"$_".ToUpper())[$a[$i++]-in65..90]})
```
Original:
```
param($a);$x=0;(($a[-1..-$a.length])|%{$_=$_.tostring().tolower();if([regex]::matches($a,"[A-Z]").index-contains$x){$_.toupper()}else{$_};$x++})-join''
```
Normal formatting:
Latest (looks best as two lines in my opinion):
```
param($a)
-join($a[$a.length..0] | %{("$_".ToLower(), "$_".ToUpper())[$a[$i++] -in 65..90]})
```
Explanation:
```
param($a)-join($a[$a.length..0]|%{("$_".ToLower(),"$_".ToUpper())[$a[$i++]-in65..90]})
param($a)
# Sets the first passed parameter to variable $a
         -join(                                                                      )
# Converts a char array to a string
               $a[$a.length..0]
# Reverses $a as a char array
                               |%{                                                  }
# Shorthand pipe to foreach loop
                                  ("$_".ToLower(),"$_".ToUpper())
# Creates an array of the looped char in lower and upper cases
                                                                 [$a[$i++]-in65..90]
# Resolves to 1 if the current index of $a is upper, which would output "$_".ToUpper() which is index 1 of the previous array
```
Original:
```
param($a)
$x = 0
(($a[-1..-$a.length]) | %{
    $_ = $_.tostring().tolower()
    if([regex]::matches($a,"[A-Z]").index -contains $x){
            $_.toupper()
        }else{
            $_
        }
        $x++
    }
) -join ''
```
First time poster here, was motivated because I rarely see PowerShell, ~~but at ~~154~~ 152 bytes on this one... I can see why!~~ Any suggestions appreciated.
I have learned that I must completely change my way of thinking to golf in code and its fun!
[Answer]
# [Dyalog APL](http://goo.gl/9KrKoM), 12 [bytes](http://meta.codegolf.stackexchange.com/a/9429/43319)
```
⌽f¨⍨⊢≠f←819⌶
```
`819⌶` is the case folding function
`f←` because its name is long, we assign it to *f*
`⊢≠f` Boolean where text differs from lower-cased text
`f¨⍨` use that (1 means uppercase, 0 means lowercase) to fold each letter...
`⌽` ... of the reversed text
Handles non-ASCII according to the Unicode Consortium's rules.
[Answer]
## CJam, 22 bytes
```
q_W%.{el\'[,65>&{eu}&}
```
[Test it here.](http://cjam.aditsu.net/#code=q_W%25.%7Bel%5C'%5B%2C65%3E%26%7Beu%7D%26%7D&input=Hello%2C%20Midnightas)
[Answer]
# Racket, 146 bytes
```
(λ(s)(build-string(string-length s)(λ(n)((if(char-upper-case?(string-ref s n))char-upcase char-downcase)(list-ref(reverse(string->list s))n)))))
```
Racket is bad at this whole "golfing" thing.
*Shrug* As always, any help with shortening this would be much appreciated.
[Answer]
# Jolf, 21 bytes
[Try it here!](http://conorobrien-foxx.github.io/Jolf/#code=zpxpZD8mzrMuX3BYaVM9cHhISHB4zrPOsw&input=SGVsbG8sIE1pZG5pZ2h0YXMKCi5R)
```
Μid?&γ._pXiS=pxHHpxγγ
```
## Explanation
```
Μid?&γ._pXiS=pxHHpxγγ
Μid                   (Μ)ap (i)nput with (d)is fucntion:
   ?        =pxHH     (H is current element) if H = lowercase(H)
    &γ._pXiS          and set γ to the uppercase entity in the reversed string
                 pxγ  lowercase γ
                    γ else, return γ
```
[Answer]
# [Perl 6](http://perl6.org), 29 bytes
```
$_=get;put .flip.samecase($_)
```
[Answer]
# C#, ~~86~~ 85 bytes
```
s=>string.Concat(s.Reverse().Select((c,i)=>s[i]>96?char.ToLower(c):char.ToUpper(c)));
```
A C# lambda where the input and the output is a string. You can try it on [.NetFiddle](https://dotnetfiddle.net/0NjPq2).
---
~~I am struggling to understand why I cant achieve to convert `char.ToLower(c)` to `c+32`. I hope to fix it!~~
12 bytes saved thanks to @PeterTaylor (`c|32` to add 32 to the ascii value of `c` and `c&~32` to substract 32). The result would be 72 bytes (but can fail on non alpha char). 
```
s=>string.Join("",s.Reverse().Select((c,i)=>(char)(s[i]>96?c|32:c&~32)));
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `r`, ~~9~~ 2 bytes
```
Ṙ•
```
[Try it online!](https://vyxal.pythonanywhere.com/#WyJyIiwiIiwi4bmY4oCiIiwiIiwiSGVsbG8iXQ==)
[Answer]
# [Julia 1.0](http://julialang.org/), ~~73, 65~~  64 bytes
```
!s=prod(titlecase(s[end-i+1]^2)[2-('@'<s[i]<'[')] for i=keys(s))
```
[Try it online!](https://tio.run/##NcqxDsIgEADQ3a@44gDE1qSd26SDg4uDcSSYEIvl9ATTw6hfj5NvfrcXoWs/pVQ8PJc0qYyZ/MWxV2x8nBrctPbcadM1So6yZ4O2l0ZqC9e0AA53/2XFWpeRQ3pDJfaeKNVwwCniHLJjAWs4uRxmjDt8QJ2IfFj9@/Yoyg8 "Julia 1.0 – Try It Online")
-9 MarcMush
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~13~~ 10 bytes
```
ŒlðUŒuT}¦n
```
[Try it online!](https://tio.run/##y0rNyan8///opJzDG0KPTioNqT20LO////8eQPF8HQXfzJS8zPSMksRiAA "Jelly – Try It Online")
Did I say this was extremely golfable by someone who understands `¦`? Turns out it's just understanding anything at all about chaining in general.
```
Œl            Lowercase the input,
   U          reverse it,
    Œu        then uppercase it
      T}¦     at indices where
  ð      n    the lowercase input doesn't equal the original input.
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 139 bytes
```
#define B v[c+~i]
#define C(x,y)isupper(x)?toupper(y):tolower(y)
i,t,c;f(char*v){for(c=strlen(v);i<c/2;i++)t=C(B,v[i]),v[i]=C(v[i],B),B=t;}
```
[Try it online!](https://tio.run/##XY7NasMwEITveoqFXKRYbWmPVdyCc8kb9GB8cPXjLCiSkWUlIaSv7spOA6F7mJ35GJaVT52U07RS2qDTUEGqZfGDDbmTLT3xM8Nh7Hsd6Il9Rn@zZ/YevfXHxRLkkUthqNy3YZ3YxfhAZTnEYLWjiQncyJc3gUXBYrmlFU81NmzRHOfFK8arMorrtEIn7ag0bIaoLH4/7z/IIwvouv9MoZ8RugiHFh2dTRs6yWF@CNbZp7ph5EIgz43lS1BCVjX2dCm8NkyQpWFo5vfQj3F4zCZo/ZevME07ba2HLx@s@gU "C (gcc) – Try It Online")
[Answer]
# [Julia 1.0](http://julialang.org/), ~~114~~ ~~92~~ 78 bytes
```
~x=(b=reverse(lowercase(x));prod(i->b[i]-32('@'<x[i]<'['<b[i]-5<'v'),keys(b)))
```
[Try it online!](https://tio.run/##yyrNyUw0rPj/v67CViPJtii1LLWoOFUjJ788tSg5Eciq0NS0LijKT9HI1LVLis6M1TU20lB3ULepALJt1KPVbcCCpjbqZeqaOtmplcUaSZqamv8dijPyyxXqlDxSc3LydRR8M1PyMtMzShKLlbhgUnqBCHZilWMUgucIBA7RCdVK/wE "Julia 1.0 – Try It Online")
* -22 bytes thanks to amelies: use `prod`
* -10 bytes thanks to MarcMush: avoid `uppercase` and `isuppercase`
* -4 bytes thanks to MarcMush: use `keys(b)` instead of `1:length(b)`
[Answer]
# PHP, 128 bytes
```
$s=$argv[1];$l=strrev($s);for($i=0;$i<strlen($s);++$i){echo(strtolower($s[$i])!==$s[$i]?strtoupper($l[$i]):strtolower($l[$i]));}
```
I may attempt to optimize this further but I'll just leave it as is for now.
[Answer]
# Octave, ~~51~~ 50 bytes
~~`@(s)merge(isupper(s),b=flip(toupper(s)),tolower(b))`~~
```
@(s)merge(s>64&s<91,b=flip(toupper(s)),tolower(b))
```
]