The Rule of Thumb for Title Capitalization According to this site a general rule recommended by The U.S. Government Printing Office Style Manual is


  Capitalize all words in titles of publications and documents, except
  a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and
  nor.


This might not be true as I'm unable to find such a recommendation in the Style Manual, but let's use this rule anyway.



The Challenge 

Given an input string consisting of lower case words delimited by spaces, output the capitalization of the string according to the following rules


The first and last word is capitalized.
All other words are capitalized, except a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and nor.


The input string will contain at least one word and each word contains at least one letter and only characters from a to z.

This is a code golf challenge, so try to use as few bytes as possible in the language of your choice. You may write a full program or a function to accomplish the task.

Testcases

"the rule of thumb for title capitalization" -&gt; "The Rule of Thumb for Title Capitalization"
"programming puzzles and code golf" -&gt; "Programming Puzzles and Code Golf"
"the many uses of the letter a" -&gt; "The Many Uses of the Letter A"
"title" -&gt; "Title"
"and and and" -&gt; "And and And"
"a an and as at but by for in nor of on or the to up" -&gt; "A an and as at but by for in nor of on or the to Up"
"on computable numbers with an application to the entscheidungsproblem" -&gt; "On Computable Numbers With an Application to the Entscheidungsproblem"
Python 2, 118 bytes

Look ma, no regex!

for w in`input()`.split():print[w.title(),w][`w`in"'a'an'and'as'at'the'by'but'for'nor'in'of'on'or'to'up'"].strip("'"),


Input must be wrapped in quotes. Output has a trailing space and no trailing newline (I assume that's okay). Verify all test cases on Ideone.

Explanation

Let's take the input a or an as our example.

Using Python 2's `x` shortcut for repr, we wrap the input in single quotes: 'a or an'. Then we split on whitespace and iterate over the words.

Inside the loop, we take the repr again. For the first and last words, this gives "'a" and "an'". For other words, it gives 'or'. We want to avoid capitalizing words if they fit the latter pattern and are in the short-words list. So we can represent the word list as the string "'a'an'...'up'" and know that the repr of any short word will be a substring.

`w` in "..." gives a boolean value, which we can treat as 0 or 1 for the purposes of indexing into the list [w.title(), w]. In short, we title-case the word if it is at the beginning, at the end, or not in the list of short words. Otherwise, we leave it alone. Fortunately, title() still works as expected with input like 'a.

Finally, we strip any single quotes from the word and print it with a trailing space.