Cattle brush off net 21 (two questions) questions

41. The sentence reversed

Topic Link
https://www.nowcoder.com/practice/0ae4a12ab0a048ee900d1536a6e98315?tpId=85&&tqId=29896&rp=16&ru=/activity/oj&qru=/ta/2017test/question-ranking
subject description
given a sentence (only contain letters and spaces) , the position of the word in the sentence reversed, the word split by a space, only one space between words, no spaces before and after. For example: (1) "hello xiao mi " -> "mi xiao hello"
Input Description
of input data a plurality of sets, each representing one line containing a sentence (sentence length is less than 1000 characters)
output descriptor
for each test example, requirements formed after the sentence output in the sentence the word inverted
example 1
input
hello xiao mi
output
mi xiao hello
Title analysis

  1. Note that multiple sets of data input.
  2. Use spaces divided character.
  3. Use reverse () output reverse character.
  4. Use join ( '') is connected characters.
var input;
while(input = readline()){
    var arr = input.split(' ').reverse();
    console.log(arr.join(' '));
}

42. Fibonacci number

Topic Link
https://www.nowcoder.com/practice/aa8ffe28ec7c4050b2aa8bc9d26710e9?tpId=2&&tqId=10856&rp=1&ru=/activity/oj&qru=/ta/front-end/question-ranking
subject description
implemented in JavaScript Fibonacci column function returns the n-th Fibonacci number. f (1) = 1, f (2) = 1 , etc.
Title Analysis

  1. When n <= 2, f (n) = 1;
  2. When n> = 3, f (n) = f (n-1) + f (n-2).
function fibonacci(n) {
    if(n <=2){
        return 1;
    }else{
        var f1 = 1;
        var f2 = 1;
        var f3;
        for(var i=3; i<=n; i++){
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
}
Published 22 original articles · won praise 0 · Views 354

Guess you like

Origin blog.csdn.net/weixin_41796393/article/details/104385705
Recommended