For those of us in the northern hemisphere, Monday is the first day of Winter, which seems a good time to check out a website that's all about the snow.
VOA: standard.2009.12.19
All right, we're-- well actually, I should say that better, we first check to see, is x 0 greater than or equal to zero, if it's not, then we come down here and we print something out, otherwise we run through a little loop to get the answer, and then we check it and we spit something out.
然后我们运行一个小循环,好了,我们现在来看看,如果x≥0或者x<,我们看这儿,我们会输出一些内容,或者我们运行一个小循环来获取答案,然后我们检验一下,然后得到结果。
First of all, having read in that value, I can check to see, is it of the right type?
首先,读一下这个值,我们可以来检查看看是不是正确的类型?
Right after the elections, basically the international news agencies were not allowed to get news and the first place you would check for the videos from Iran, the protest videos and so on, was just on Facebook."
VOA: standard.2010.07.23
First, I'm going to do a sanity check strlen so we've used string length, strlen, before.
首先,我先做一个检查,我们以前使用过字符串长度函数。
So that's just a little bit of a check for yourself, and it should make sense because what you're doing is you're calculating the difference between energy levels, so you just need to flip around which you put first to end up with a positive number here, and that's a little bit of a check that you can do what yourself.
所以你们总要确保括号,离得这项是正的,这是你们自己,可以做的检查,这事很有道理的,因为你们做的是计算能量差,所以你需要调整顺序来保证一个正数,这是你们自己可以做的检查。
Otherwise I'm going to check to see is the first and last, there's that - 1 indexing, is the first and last element of the string the same?
是第一个还是最后一个,这就是这边-1的索引内容,这个字符串的第一个,和最后一个的内容是否相同呢?
The easy thing to do would be the following: start at the front end of the list, check the first element. If it's the thing I'm looking for, I'm done. It's there. If not, move on to the next element. And keep doing that.
从数组的第一个元素开始:,如果这是目标元素那么结束,如果不是的话就继续比较下面的元素,并一直这么比较下去,但如果,在某一点我发现我要寻找的数字。
But that merging process only takes N steps, N*log N so that's N times log of N. Now, it's a little tricky to reason through this perhaps the first time, let's just take a very simple example and see if we can do a little sanity check here.
但这个合并过程只需要N步,所以时间复杂度是,第一次对此进行推论可能会有点儿棘手,我们举一个简单的例子,看看我们能否做一些完整性的检查。
So conceptually the key difference here, besides the syntax looking slightly different, it just means that if you want a chunk of code to execute no matter what initially, ; you can use the do while loop; if you want to check a condition first, you can use the while loop.
所以概念上,则关键的区别是,除了语法看起来有点不同,它的意思是如果你想要一段代码,最初无论如何都要执行,你就可以用do,while循环;,如果你想要先检查条件,你可以用while循环。
If I come into this code, I'm going to check this branch first, if it's not true, ah, there's a return at the end of that branch. If it is true, I do that, and then I've got a second test. If it's true, return I return, otherwise a return.
但是如果我们看看这里,如果我看这段程序,我会先检查这一部分,如果它是假的,啊,这部分分支结尾有一个。
Well, now I go through code very much like what I did for max val in the first place. I check whether it's 0, et cetera, et cetera.
现在我会捋一遍代码,就像我之前捋maxval函数一样,我会检查它是不是0等等等等。
Check first is N less than 2.
首先检查N是否小于。
But notice what this does. The first thing it does is, it says, let's check and make sure x is greater than or equal to 0. If it isn't, notice what's going to happen. None of that block is going to get executed, and it's going to come down here and print out a useful piece of information, which says, hey, you gave me a negative number. I don't know how to do this.
做的是和以前一样的事情,但是注释它做了什么,第一件做的事情就是,程序说,要去检查并且确信x是大于等于0的,如果不是的话,请注意会发生什么,下面的代码都不会被执行,程序会到这里来然后显示一些有用的信息,信息会说,嘿,你给了我一个负数,我不知道该怎么弄这个了。
应用推荐