题解 | #KiKi定义电子日历类#

KiKi定义电子日历类

https://www.nowcoder.com/practice/e4c67097cdb242d9a3f38b7cfe839396

#include <stdio.h>

typedef struct date {
    int day;
    int month;
    int year;
}date_t;

void init(date_t* d) {
    d->day = 0;
    d->month = 0;
    d->year = 0;
}

void constructor(date_t* d, int day, int month, int year) {
    d->day = day;
    d->month = month;
    d->year = year;
}

void show(date_t* t) {
    printf("%d/%d/%d\n", t->day, t->month,t->year);
}

int main() {
    int day, month, year;
    while (scanf("%d %d %d", &year, &month, &day) != EOF) { // 注意 while 处理多个 case
        // 64 位输出请用 printf("%lld") to 
        date_t* d = (date_t*)malloc(sizeof(date_t));
        constructor(d, day, month, year);
        show(d);
    }
    return 0;
}

全部评论

相关推荐

2025-12-03 03:32
安徽大学 Java
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务