यह ढक्कन की तरह है


29

अक्टूबर 22 अंतर्राष्ट्रीय अंतरराष्ट्रीय ताला दिन है ! UNFORTUNATELY, आलमी कैप लॉक की महिमा का पता नहीं लगाता है। वे इसे "OBNOXIOUS" या "पसंद कर रहे हैं" या कुछ गैर-शब्द को देखता है। अपने आप को पूरी तरह से ILLOGICAL और INNLLTS से मिलाने के लिए, कृपया एक कार्यक्रम को सामान्य रूप से सामान्य पाठ "SENBBLE" या "" "" "" जैसे "" "" "" के रूप में पेश करें, जो लोगों को आकर्षित करने में सक्षम हैं।

विवरण

आपके समाधान के लिए इनपुट और आउटपुट दोनों तार होंगे जिनमें केवल मुद्रण योग्य ASCII वर्ण होते हैं।

इनपुट स्ट्रिंग में शून्य या अधिक कैप्स लॉक रन होंगे । एक कैप लॉक रन (या शॉर्ट के लिए सीएलआर) को निम्नलिखित के रूप में परिभाषित किया गया है:

  • सीएलआर में कोई लोअरकेस अक्षर नहीं होना चाहिए ( a-z), एक शब्द के पहले चरित्र को छोड़कर

    • इस चुनौती के प्रयोजनों के लिए एक शब्द , गैर-रिक्त स्थान का एक क्रम है। तो, PPCG, correcthorsebatterystaple, और jkl#@_>00()@#__f-023\f[सभी माना जाता शब्द है।
  • सीएलआर में कम से कम एक स्थान होना चाहिए; इसलिए, यह कम से कम दो शब्द होना चाहिए ।

  • सीएलआर में प्रत्येक शब्द में कम से कम दो अक्षर ( A-Za-z) होने चाहिए।

    • ध्यान दें कि यह सीएलआर को संदर्भित करता है, बिना किसी भी आसपास के पात्रों के बिना जो सीएलआर में शामिल नहीं हो सकते हैं। उदाहरण के लिए, है एक CLR क्योंकि स्ट्रिंग से ही है शब्द कम से कम दो पत्र के साथ है।foO BarO B

सीएलआर को "लालच" से पार्स किया जाना चाहिए - यह है, आपको हमेशा सबसे लंबे सीएलआर को ढूंढना चाहिए।

एक बार जब आप इनपुट स्ट्रिंग में सभी सीएलआर की पहचान कर लेते हैं, तो सीएलआर के अंदर सभी अक्षरों के मामले को स्वैप करें और परिणामी स्ट्रिंग को आउटपुट करें।

परीक्षण के मामलों

पहली पंक्ति इनपुट है, और दूसरी आउटपुट है। इनपुट के बोल्ड भाग सब्सट्रिंग हैं जिन्हें सीएलआर माना जाता है।

CAPS LOCK IS THE BEST!
caps lock is the best!
I really LOVE pROGRAMMING pUZZLES AND cOde Golf!
I really love Programming Puzzles and Code Golf!
This is a challenge on PPCG. This is a test CASE. TEST
This is a challenge on PPCG. This is a test case. test
LorEM iPSUM DOLoR sIT amet, conSECTETur ADIPISciNG eLIT. MAECENAS iD orci
Lorem Ipsum doloR sIT amet, conSECTETur ADIPIScing Elit. maecenas Id orci
;'>}{/[]'"A*(389971(*(#$&B#@*(% c'>#{@D#$! :,>/;[e.[{$893F
;'>}{/[]'"a*(389971(*(#$&b#@*(% C'>#{@d#$! :,>/;[e.[{$893F
iT'S cAPS lOCK DAY!!! cELebraTE THis WONDERFUL key
It's Caps Lock day!!! Celebrate this WONDERFUL key
aBcDE fGHIj KLmNO pQrST (uVwXY) ZZ___Zz__Z
aBcde Fghij KLmno PqrST (uVwxy) zz___zz__Z
#aA# aA
#aA# aA

नियम

  • आप मान सकते हैं कि इनपुट में कभी भी एक पंक्ति में दो या अधिक स्थान नहीं होंगे, और इसमें कभी भी अग्रणी या अनुगामी स्थान नहीं होगा।

  • यदि आपका पूरा कोड सीएलआर है तो 20% बोनस (.8 से अपनी कोड लंबाई गुणा करें)। ;) (ज्यादातर सिर्फ मनोरंजन के लिए, क्योंकि यह संभावना नहीं है कि जीतने वाले के पास यह बोनस होगा)

  • यह , इसलिए बाइट्स में सबसे छोटा कोड जीत जाता है।


16
कृपया, चिल्लाना बंद करें।
TheDoctor

4
इसके अलावा, टेस्ट केस # 3 के लिए, पूंजीकृत पीपीसीजी को कम नहीं किया जाएगा? ( PPCG. Tएक स्थान होता है)
TheDoctor


2
@ डेनिस मैंने पढ़ा है कि मॉर्टी की आवाज में (रिक और मोर्टी से), बी / सी वह "रिक" से बात कर रहा है।
mbomb007

1
"अपने कोड के लिए बोनस अंक एक CLR होने के नाते" बस मुझे LOLCODE में ऐसा करना चाहता है ...
बिल्ली

जवाबों:


4

CJam, 100 86 83 81 बाइट्स

Ml{_,),{1$<_S/(4$!>\1f>s+_eu=*S%_{'[,_el^:Af&s,2<},!*1>},_{W=/(AA26m>er}{;(}?\s}h

प्रयास करें इस बेला CJam दुभाषिया में या एक ही बार में सभी प्रकार के परीक्षण की पुष्टि

कलन विधि

  1. पहले चरित्र से शुरू होने वाले सबसे लंबे समय तक संभव सीएलआर की पहचान करें।

  2. यदि यह मौजूद है, तो इसके मामले को स्वैप करें, इसे प्रिंट करें, और इसे स्ट्रिंग की शुरुआत से हटा दें।

    एल्स, स्ट्रिंग की शुरुआत से एक भी चरित्र को हटा दें, और इसे अनमॉडिफाइड प्रिंट करें।

  3. यदि अधिक वर्ण बचे हैं, तो चरण 1 पर वापस जाएं।

यह काम किस प्रकार करता है

Ml         e# Push an empty string and a line from STDIN.
{          e# Do:
  _,       e#   Copy the string on the stack and compute its length (L).
  ),       e#   Push [0 ... L].
  {        e#   Filter; for each integer I in that array:
    1$<    e#     Copy the string and keep its first I characters.
    _S/    e#     Push a copy and split at spaces.
    (      e#     Shift out the first word.
    4$!    e#     Push the logical NOT of the fifth topmost item of the stack.
           e#     This pushes 1 for the empty string on the bottom, and 0
           e#     for non-empty strings and printable characters.
    >      e#     Remove that many characters from the beginning of the first word.
           e#     This will remove the first character iff the string on the
           e#     stack is the entire input. This is to account for the fact that
           e#     the first word is not preceded by a space.
    \1f>   e#     Remove the first character of all remaining words.
    s+     e#     Concatenate all of them.
    _eu=   e#     Convert a copy to uppercase and check for equality.
    *      e#     Repeat the I characters 1 or 0 times.
    S%_    e#     Split at runs of spaces, and push a copy.
    {      e#     Filter; for each non-empty word:
      '[,  e#       Push the string of all ASCII characters up to 'Z'.
      _el  e#       Push a copy and convert to lowercase.
      ^    e#       Perform symmetric difference, pushing all letters (both cases).
      :A   e#       Store the result in A.
      f&s  e#       Intersect A with each character of the word. Cast to string.
      s    e#       This removes all non-letters from the word.
      ,2<  e#       Count the letters, and compare the result to 2.
    },     e#     If there are less than 2 letters, keep the word.
    !      e#     Push the logical NOT of the result.
           e#     This pushes 1 iff all words contain enough letters.
    *      e#     Repeat the array of words that many times.
    1>     e#     Remove the first word.
  },       e#   Keep I if there are still words left.
  _{       e#   If at least one I was kept:
    W=     e#     Select the last (highest) one.
    /      e#     Split the string on the stack into chunks of that length.
    (      e#     Shift out the first chunk.
    AA26m> e#     Push "A...Za...z" and "a...zA...Z".
    er     e#     Perform transliteration to swap cases.
  }{       e#   Else:
    ;      e#     Discard the filtered array.
    (      e#     Shift out the first character of the string on the stack.
  }?       e#
  \s       e#   Swap the shifted out chunk/character with the rest of the string.
}h         e# If the remainder of the string is non-empty, repeat.

5
यह कैसे काम करता है: पियानो पर 20 ई # नोट चलाता है।
kirbyfan64sos

मैंने कुछ और विवरण जोड़े हैं। : पी
डेनिस

2

पर्ल, 96 82 80 बाइट्स

-pe'$y=qr/[^a-z ]{2,}|\b\S[^a-z ]+/;s#$y( $y)+#join$,,map{uc eq$_?lc:uc}$&=~/./g#eg'

सभी टेस्ट पास करता है। से STDIN, प्रिंट को इनपुट मान लेता है STDOUT

यह काम किस प्रकार करता है:

  • सेटअप एक रेगेक्स ( $y) जो मेल खाता है

    • कम से कम दो गैर-लोअरकेस, गैर-व्हाट्सएप वर्ण OR
    • एक शब्द सीमा, उसके बाद एक गैर-व्हाट्सएप चरित्र, उसके बाद एक या अधिक गैर-लोअरकेस, गैर-व्हाट्सएप वर्ण
  • मैच के स्थान-पृथक स्ट्रिंग्स के कई उदाहरणों का मिलान करें $y, s///इनवर्ट केस का उपयोग करें

मुझे यकीन है कि सुधार की गुंजाइश है। यदि पूरी join-map-splitडील से छुटकारा पाने का कोई तरीका है तो बोनस के लिए अर्हता प्राप्त करने का मौका हो सकता है :)


1
के a-zबजाय का उपयोग करके आप कुछ बाइट्स बचा सकते हैं [:lower:]। इसके अलावा, -peआमतौर पर 1 बाइट के रूप में गिना जाता है, और सिंगल बाइट शून्य बाइट के रूप में गिना जाता है।
डेनिस

@ डेनिस: सुझाव के लिए धन्यवाद! कि मुझे कुछ हद तक कोड को सरल बनाने की अनुमति दी - पर्ल वन-लाइनर्स के बारे में आपके दिशानिर्देशों के अनुसार 81 से नीचे
Zaid

यह उत्तर अमान्य है, क्योंकि यह अंतिम परीक्षण मामले (हाल ही में डेनिस के सौजन्य से जोड़ा गया) को पास नहीं करता है।
दरवाज़े

2

जावास्क्रिप्ट, 193

decapslock =

a=>a.replace(/(^[a-z][^a-z ]+|[^a-z ]{2,})( [a-z][^a-z ]+| [^a-z ]{2,})+/g,b=>b.split` `.some(f=>f.split(/[a-z]/i).length<3)?b:b.split``.map(e=>e==(E=e.toUpperCase())?e.toLowerCase():E).join``)
<!-- Snippet UI -->
<input placeholder='sAMPLE tEXT' oninput="document.getElementsByTagName('p')[0].innerText=decapslock(this.value)" />
<p></p>

स्पष्टीकरण:

a=>a.replace(/* giant regex */,
  b=>
    b.split` `.some(
      f=>
        f.split(/[a-z]/i).length < 3   // check for 2+ letters
    )
      ? b                              // .some() immediately returns true if it's invalid
      : b.split``.map(                 // otherwise it's valid, so flip case
          e=>
            e == (E = e.toUpperCase()) // is it uppercase?
              ? e.toLowerCase()        // change it to LC
              : E                      // change it to UC, which was already done for
                                       // the case check
            ).join``
        )
(
^[a-z][^a-z ]+ // check for a CLR starting at the beginning with LC
|
[^a-z ]{2,}    // check for a CLR that begins in the middle of a word or starts at the
               // beginning with UC
               // in both cases, 2+ letters are required
)
(
 [a-z][^a-z ]+ // check for the next word of the CLR, starting with LC
|
 [^a-z ]{2,}   // check for the next word of the CLR, starting with UC
)+             // check for 1 or more next words

यह उत्तर अमान्य है, क्योंकि यह अंतिम परीक्षण मामले (हाल ही में डेनिस के सौजन्य से जोड़ा गया) को पास नहीं करता है।
दरवाज़े

अर्घ, फिक्स ने इसमें कई टन बाइट्स जोड़े। लेकिन, यह तय है
DankMemes
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.