前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CS50_week3 Algorithms

CS50_week3 Algorithms

原创
作者头像
greatak
发布2024-09-06 15:31:50
550
发布2024-09-06 15:31:50
举报
文章被收录于专栏:cs50
代码语言:c
复制
#include <cs50.h>
#include <stdio.h>

int main(void)
{
    string strings[] = {"battleship", "boot", "cannon", "iron", "thimble", "top hat"};

    string s = get_string("String: ");

    for (int i = 0; i < 6; i++)
    {
        if (strings[i] == s)
        {
            printf("Found\n");
            return 0;
        }
    }
    printf("Not Found\n");
    return 1;
}

不能用string[i] == s来比较string
不能用string[i] == s来比较string
代码语言:c
复制
#include <cs50.h>
#include <stdio.h>
#include <string.h>
typedef struct
{
    string name;
    string number;
}
person;


int main(void)
{
    person people[3];

    people[0].name = "Carter";
    people[0].number = "+1-617-495-1000";

    people[1].name = "David";
    people[1].number = "+1-617-495-1000";

    people[2].name = "John";
    people[2].number = "+1-949-468-2750";

    string name = get_string("Name: ");

    for (int i = 0; i < 3; i++)
    {
        if (strcmp(people[i].name, name) == 0)
        {
            printf("Found %s\n", people[i].number);

            return 0;
        }
    }
    printf("Not Found\n");
    return 1;
}

recursion

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • recursion
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档