OK. I get the two values in, what do I need to do, well, you sort of know that, right?
好,有了这两个输入值了,我接下来将要做的,你知道对不对?
One of the things you could imagine is just try it on and input, see how long it takes.
你们想出来的方法只是可能就是通过,输入来试试,看运行时间会有多长。
printf I have my includes, standard IO's; so I can use print F, but then I had this thing called a prototype.
我包含了标准输入输出文件,所以我可以使用,然后我有这个原型。
I mean sometimes if you have things that are a mixture of foods, like you go out for Chinese food or you have a casserole somewhere, or you have some dish of vegetables mixed together, how do you make sense of that when it comes to entering these things into a record.
我是说,有时候有一堆食物在你面前,如出去吃中餐,或你面前有一份大杂烩,又或者是很多蔬菜混合在一块,在输入饮食记录的时候,怎样才能让你输入的东西有意义呢
Or maybe I could donate bone marrow and those stem cells could be given to other people in the same way that blood can be given to other people by matching and making sure that immunologically my cells were compatible with you; there's a lot of interest in that.
或者我可以捐献骨髓,而那些干细胞,可以使用和输血同样的方法,通过配型来确认我的免疫细胞和你的匹配,从而把我的干细胞,输入给你,这里面有很多有趣的东西
It's just how much heat is involved when we change the temperature. Now, the products have some heat capacity associated with them right, it takes a certain amount of heat if we make their temperature change, to either put it in or take it away, depending on which direction the temperature is changing.
问题就是当我们改变温度时,有多少热量发生了转移,生成物具有一定的热容,如果我们改变,它们的温度,就要输入或,提取一定的热量,这取决于温度改变的方向。
And in fact if I go off and run this, OK, what I was printing here was s 1 dot length, and that's -- What is it doing?
他们就是一些有结构的实例,实际上如果我去运行下这个,好,我这里输入的?
Something that takes two inputs, a left operant - and a right operant and it just returns a Boolean value is-- or rather it returns a left to right value.
它有两个输入,一个是左边的作用物,一个是右边的作用物,然后返回一个布尔值-,或者更确切地说,返回一个从左到右的值。
If I decide there's a better way to get input, and there is, then I can make it to change what I don't have to change the code that uses the input.
如果我觉得有更好的获取输入的方法,我可以直接改去用这种方式,而不用更改使用了,输入处的代码。
So if your word game doesn't work when the words are 12 letters long, instead of continuing to debug 12 letter hands see if you can make it fail on a three letter hand.
因此如果你的单词游戏当输入单词,有12个字母的时候没法运行了,看看输入三个字母的单词它,能不能正常运行吧。
We're going to build up this taxonomy if you like, but the reason it's relevant is, associated with each one of those types is a set of operators that expect certain types of input in order to do their job.
我们将会建立这种分类,但是这相关的原因是,对于每种类型都有,和之对应的一个操作集,这个操作机对一些输入,做出规定的操作。
Now in this case, it's clear that I'm not only saying this function takes an input, I also have to give that input a name.
在这种情况,很清楚的,我不只是说明这个函数有一个输入,我还要给那个输入一个名字。
So one of the things I didn't say, it's sort of implicit here, is what is the thing I measuring the size of the problem in?
我有一点没有提及,这有点含蓄,这一点就是我怎么,来度量输入问题的大小呢?,一个数组的大小怎么来定义呢?
If you want to get some input from the user, my God I don't want to have to program it to low level zero and 1 just to get keys from the keyboard; please let there have been someone who does that for me and indeed there are an increasingly sophisticated options that you can pull off the shelf.
如果你想获得一些用户的输入数据,我的上帝,我可不希望在键盘上敲入0,1的低水平方式来编程;,希望有个人能帮我做这件事吧,但是现有的选择,也变得日益复杂了。
Last thing to say is why would you want to have exceptions? Well, let's go back to that case of inputting a simple little floating point.
最后要讲的是为什么有异常处理?,回到输入一个简单的小浮点数的例子,如果我期望主要是。
And check the answers, and say yeah that's what we expected. But it also involves reasoning. About why that's an appropriate set of inputs to test it on it.
然后说对,这就是我想要的结果,但是它跟推理也有关系,表现在关于为什么这是一个,测试我们程序的适合的输入集。
I'm going to have it take in as input how many legs I got, how many heads do I have, and I just want to write a little loop.
这就是解决问题的思路,我将要输入我有多少条腿,以及我有多少只头。
But there's an important thing going on here, if I in fact wanted to combine those into a string I should have told the machine to do that, and I can do that, by explicitly saying, take that, which is a number, then add it to that string.
但是这里有个很重要的事情,实际上想要把这些加到一个字符串里面去,我应该告诉计算机去做这个,我应该这么做,通过明确的输入,也就是把这个对象,一个数字,然后把它加到一个字符串里面去。
That's the question we're going to try and address. If we can do this, this is good, because first of all, it removes any questions about what machine I'm running on, it's talking about fundamentally, how hard is this problem, and the second thing is, it is going to do it specifically in terms of the input. Which is one of the things that I was worried about.
这是一个我们接下来要去,尝试和解决的问题,如果我们能做到的话会很不错,因为首先,它解决了结果可能和我,运行的计算机有关系的问题,因为这从根本了告诉了,我们这个问题的复杂度,第二件事情,就是这种方法可以依据输入的大小来计算,而这正是我最担心的地方。
I think one of the classic ones for strings is called the Rabin-Karp algorithm. And it's simply the same idea that you have a mapping from your import into a set of integers.
我认为字符串哈希,最经典的是Rabin-Karp算法,它只是简单的相同概念,你有一个映射关系将你的输入映射成一组数字。
So when you have a function called GetString, -- that means it's going to get a string from the user -- -- prompt the user for a string -- whereas printf is literally going to print it, not to paper, but to the screen.
所以当你有一个叫做GetSting的函数,它的意思是从用户那获得一个字符串-,提示用户输入一个字符串-,然而printf的确是用来打印的,不是在纸上,而是在屏幕上。
We own our own phone number, that allows you to input key strokes like you would any system and this is an example of what we call CS50 Voice.
我们都有电话号码,这就让我们可以输入任意的数字,然后这是CS50,Voice的一个例子。
That in many cases, I can gain efficiency if I'm willing to give up space. Having said that though, there may still be a problem, or there ought to be a problem that may be bugging you slightly, which is how do I guarantee that my hash function takes any input into exactly one spot in the storage space?
普遍存在的增益和权衡,在许多的例子中,可以通过牺牲空间而得到效率方面的增加,话说回来,仍然存在一个问题,或者应该会有一个问题困扰着你,就是我如何保证我的哈希函数能够准确将,任一输入映射到相应的唯一的存贮空间中去?
F-O-O in lowercase and, in fact, foo it is buggy because I typed lowercase F-O-O and FOO yet I get back capital F-O-O as both the original and the copy and that's simply because I haven't done this correctly.
小写的f-o-o,实际上,它是有bug的,因为我输入小写的,而我得到的原始的和拷贝的都是大写的,简单说,我处理错了。
What value of inputs, what values of x will this run correctly for?
这个程序正常运行的话对于输入的值,也就是x的值,有什么要求呢?
cs50 h It's not called standard io.h, it's called cs50.h. That's where the code we wrote for you will live and then we'll see how to do this in examples today onward but we wrote for you some tools, some functions that calls GetChar for get a character.
当然不是标准输入输出库了,而是叫做,这里面有一些我们写的代码,等一下我会举几个例子,我们写了一些函数,比如GetChar,意思是得到一个变量。
I certainly don't want to assume they're always going to type a three-letter or a four-letter or a two-letter word I want some dynamism but that's fine because get string can get a string of any length, I can then use the string length function to just ask while the program is running how big is the string that I was handed?
当然我不能假设他总是,输入3个字符或4个字符,或2个字符的单词,我想要动态地分配,因为GetString可以获得任意长度的字符串,然后我可以使用strlen函数,来得到那个我传递的字符串,有多长?
And when you call a function, one of the things X that happens is whatever your passing in, for instance, X, ; and if this is A, this thing gets copied into A; so at that moment in time of calling increment, I actually have two copies of the same value in memory but they're referred to by different names.
当你调用一个函数,其中发生的一件事情是,不管你输入什么,比如,或者是A,它把这个东西复制到A中;,调用increment的时候,实际上在内存中,有两个同样的值的内存块,但是它们有不同的名字。
Why is this much nice? Well, that's a handy piece of code. Because imagine I've got that now, and I can now store that away in some file name, input dot p y, and import into every one of my procedure functions, pardon me, my files of procedures, because it's a standard way of now giving me the input.
为什么这样很好呢?,这是一段很好用的代码,因为想象下如果我有了这段代码,我能把它用某个文件名保存起来,后缀是。py,导入到所有的处理函数中,抱歉,我的处理文件,因为这是一个标准的输入方法。
应用推荐