Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Capitalize String

Given a string, capitalize it. By capitalization I mean conTeNT-lENgth changes to Content-Length. In the example I showed the string with 2 words with - as the word boundary. However I expect you to write the code for the string containing any number of words separated by a single character as the boundary. This boundary may change across the string.

Conditions

  1. using regular expressions is not allowed.
  2. there could be any number of words in a sentence(string).
  3. each word will consist of English letters[a-zA-Z] of any case.
  4. different words in the sentence will be separated by a single character. This character will only be any one of -, ., , /, &, #. You can safely assume that sentence will not contain any other character except the mentioned ones.
  5. word boundaries should be preserved in the output.
  6. shortest code wins.

For example your program should output Begin/With.Type&Content for BeGin/wITH.tyPE&conTeNt.

Some test cases:
 "aGeNT ACcEpT/LEngTh-tYPe USeR raNgE.TyPe" 
 "type&AgeNt/CC/COnteNt lEnGth#acCePT/AgeNt.RAnGe-Cc/contEnt/cODe" 
 "cc/rEspoNCe.lEngtH#tYpE-witH&UsEr/bEgIN&uSer.AGEnT&begIn/aCCEPt/Cc" 
 "lENgTH#USeR.tYpE/BeGiN&LENGth tYpe/ACCEpt#rANge/codE&AnD-ACCepT/ConTenT" 
 "contENT/ACcEpT" 
 "BeGin/wITH.tyPE&conTeNt"
 "Code.cc#User.lenGTh-USer-AND&tyPE TypE&leNgtH.tYPe usER.UseR&with" 
 "RaNgE&COnTeNT WITh CoNTENT-TypE tyPe"
 "BEgin COdE#uSeR#aGeNt.USeR"
 "TypE LENGth"

Answer*

Draft saved
Draft discarded
Cancel
5
  • \$\begingroup\$ while 1:print(input.title()) is a shorter equivalent for the last piece of code. \$\endgroup\$ Commented Dec 17, 2013 at 14:44
  • 1
    \$\begingroup\$ @RamchandraApte I'm not sure is it allowed or not. Your code will die with an EOFError as soon as its hits the EOF \$\endgroup\$ Commented Dec 17, 2013 at 15:08
  • 1
    \$\begingroup\$ I think the general consensus for golfs is that as long as the output is correct, errors don't matter \$\endgroup\$ Commented Dec 17, 2013 at 23:26
  • \$\begingroup\$ Dang; as soon as I saw this question, I thought of this, but you beat me to it. +1 \$\endgroup\$ Commented Dec 18, 2013 at 6:38
  • \$\begingroup\$ +1 I like this better than the golfscript one because it doesn't look like an obscenity. \$\endgroup\$ Commented Jan 1, 2014 at 22:58

AltStyle によって変換されたページ (->オリジナル) /