Gimbap kesici olun


23

Gimbap (김밥) biraz suşi rulo gibi görünüyor, Kore yemeğidir.

İşte Kore ifade Gimbap'ı temsil ediyor: @))))))))))

Görevin ASCII Gimbap kesici yapmak.

Kural

Giriş yalnızca @ve ile yapılan dizedir ).

Çıktı , geçerli her Gimbap’ı keser) ve @aralarına ekler . Örneğin Yani @))için @) @).

Geçerli Gimbap@ herhangi bir miktarla başlar ve ardından gelir ).

Geçerli bir Gimbap yoksa, çıktı boştur.

Giriş ve çıkış

Input | Output
@))))) | @) @) @) @) @)
@))))))) | @) @) @) @) @) @) @)
@))@))) | @) @) @) @) @)
@) | @)
)) | 
@ | 
@@)@@@))) | @) @) @) @)
@)@)@)) | @) @) @) @)
@@@)) | @) @)
))@) | @)

Kazanma koşulu

Bu , yani en kısa kod kazanır.

dan kum havuzu


2
Çıkışı bir kopyası" na kural eşdeğerdir @) her için )girdi herhangi önce bu saymazsak içinde @? Bizim çıkış sonunda bir boşluk gibi içerebilir "@) @) "?
XNOR

Bu. Ve çıktı takip eden bir boşluk içerebilir.
LegenDUST

Boşluk içeren bir dize mi basmamız gerekiyor yoksa bir dilim dilimi mi basabiliriz? Ayrıca, bu 2 karakterle sınırlı mıyız yoksa istediğimiz 2 karakterden birini kullanabilir miyiz?
Shaggy

İlk kez "Gimp-yarasa kargaşası? Ne?"
Draco18,

Yanıtlar:




5

C (gcc) , 53 bayt

i;f(char*_){for(i=1;*_;!i&*_++&&printf("@) "))i&=*_;}

Çevrimiçi deneyin!

i;f(char*_){for(    *_;                      )      }   //loop over the string:
                i=1;   !i&                    i&=*_;    //skip leading `)`s
                       !i&*_++&&printf("@) ")           //and print "@) "for each `)` thereafter







2

05AB1E , 12 bayt

')Û'@KS'@ìðý

Çevrimiçi deneyin!

açıklama

')Û            # trim leading ")"
   '@K         # remove all "@"
      S        # split to list of characters
       '@ì     # prepend "@" to each
          ðý   # join on spaces

2

Toplu iş, 58 bayt

@set s=%1@
@set s=%s:*@=(%
@set s=%s:@=%
@echo%s:)=@) %

Komut satırı parametresi olarak girdi alır. Açıklama:

@set s=%1@

Girdide @herhangi bir şey bulunmuyorsa sonekini ekleyiniz .

@set s=%s:*@=(%

İlke kadar silin , dizenin boş olmadığından emin olmak için @a ile değiştirin ((çünkü %:%boş dizelerde çalışmaz). (Ayrıca yapar echodize geri kalanı boşsa işi.

@set s=%s:@=%

Kalan @s'yi silin .

@echo%s:)=@) %

Kalanları genişletin ).



2

Japt v2.0a0 -S, 15 bayt

r/^\)+|@/ ¬mi'@

Dene

r/^\)+|@/ ¬mi'@     :Implicit input of string
r                   :Remove
 /^\)+|@/           :  "@"s and leading ")"s
          ¬         :Split
           m        :Map
            i'@     :  Prepend "@"
                    :Implicit output, joined with spaces

Alternatif

e/^\)/ è\) Æ"@)

Dene

e/^\)/ è\) Æ"@)     :Implicit input of string
e                   :Recursively remove
 /^\)/              :  Leading ")"
       è\)          :Count remaining ")"s
           Æ        :Map the range [0,Count)
            "@)     :  Literal string
                    :Implicit output, joined with spaces





1

Ruby -p , 28 bayt

$_= ~/@/&&'@) '*$'.count(?))

Çevrimiçi deneyin!

açıklama

                                # -p gets a line of STDIN
$_=                             # Set output to
    ~/@/                        # Find first '@' in input
                                # nil (falsey) if not found
        &&                      # If found, set output to
          '@) '                 # Sliced gimbap
               *                # Repeat
                $'              # In the string after the first '@',
                  .count(?))    # ... count the number of ')'
                                # -p outputs the contents of $_
                                # nil outputs as a blank string


1

sed , 30 bayt

s/)\?@\()\?\)/\1/g; s/)/@) /gp

Çevrimiçi deneyin!


PPCG'ye Hoşgeldiniz. Maalesef, kodunuz liderleri )ve birden @fazlasını doğru şekilde işleyemez . Ve çevrimiçi denemeye ne dersiniz ?
LegenDUST

1
5. veya son örnekte görebileceğiniz gibi, liderlerin )göz ardı edilmesi gerekir.
LegenDUST

@LegenDUST, haklısın! o kadar kolay değildi. Sanırım çalışma sürümü çok daha çirkin
Vicente Bolea

28 karakter: s / ^) * //; s / [^)] // g; s /./@) / gp
jnfnt


1

Pyth , 20 bayt

*?}\@z/>zxz\@\)0"@) 

Çevrimiçi deneyin!Programın sonunda bir boşluk olduğunu unutmayın. Bu, (ya da daha doğrusu, başlamış) Python 2 cevabının oldukça doğrudan bir çevirisidir (ilk kısım şaşırtıcı derecede zor olsa da).

Açıklama:

*            # repeat string
  ?          # repeat count: ternary
    }\@z     # condition: check whether input contains @
    /        # if condition is true: count occurrences of one string in another
      >      # array slice: all elements of array (or string) from a specific index and upwards
        z    # the thing to slice (input)
        xz\@ # the index first occurrence of \@ in z
      \)     # string to count occurrences of (\x is shorthand for "x")
    0        # value when ternary condition is false
  "@) "      # the string to be repeated (automatically terminated by end-of-line)

1

krrp , 63 bayt

^":\L,^*':?#?E'E!-@1#!r'?=#!f'$64.-?*L$64.L$41.L$32.-@0#!r'.0".

Çevrimiçi deneyin!


açıklama

^":                   ~ take the string as a parameter named `"`
 \L                   ~ import the list module
 ,^*':                ~ apply a binary function
  ?#?E'               ~  if the string is empty,
   E                  ~   return the empty string; else
   !-@1#!r'           ~   define `-` as the cut Gimbap
   ?=#!f'$64.         ~    if an at sign is seen,
    -                 ~    return the cut Gimbap; else
    ?*                ~    if an at sign has been seen,
     L$64.L$41.L$32.- ~     return a Gimbap piece together
                      ~     with freshly cut Gimbap; else
     @0#!r'           ~     proceed to cut
 .0".                 ~ to zero and the above taken string

Çevrimiçi deneyin!


1

PowerShell , 42 bayt

''+($args|sls '(?<=@.*)\)'-a|% m*|%{'@)'})

Çevrimiçi deneyin!

unrolled:

$arrayOfCuttedGimbaps = $args|select-string '(?<=@.*)\)' -AllMatches|% Matches|%{'@)'}
''+($arrayOfCuttedGimbaps)    # toString and output
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.