lecture3

发布时间 2023-12-21 19:08:18作者: viewoverlook

lecture3

Running time

符号:

  • O:大O符号,表示上限
  • \(\Omega\):大Omega符号,表示下限
  • \(\Theta\):大Theta符号,表示上下限

seach.c

#include <cs50.h>
#include <stdio.h>
int main(void){
    string strings[] = {"Bill", "Charlie", "Fred", "George", "Ginny", "Percy", "Ron"};
    string s=get_string("String: ");
    for (int i=0; i<7; i++){
        if (strings[i]==s){
            printf("Found\n");
            return 0;
        }
    }
    return 1;
}

注意strings[i]==s这个比较是不对的,因为这是比较两个指针的地址,而不是比较两个字符串的内容,应该使用strcmp函数