how to search for a capital letter within a string and return the list of words with and without capital letters

前端 未结 9 1214
无人共我
无人共我 2020-12-18 23:23

My homework assignment is to Write a program that reads a string from the user and creates a list of words from the input.Create two lists, one containing the words that con

9条回答
  •  忘掉有多难
    2020-12-18 23:32

    Sounds like regexs would be easier for the first part of the problem (a regex that just looks for [A-Z] should do the trick).

    For the second part, I'd recommend using two lists, as that's an easy way to print everything out in one for loop. Have one list of non_upper_words and one of upper_words.

    So, the basic outline of the program would be:

    1. split the string into an array of words.
    2. for each word in array: if regex returns true, add to upper_words. Else: add to non_upper_words.
    3. print each word in the first array and then in the second.

    I wrote this out in pseudo-code because it's a programming assignment, so you should really write the actual code yourself. Hope it helps!

提交回复
热议问题