A-Ares, Toilet Ares 2021牛客多校8

链接:https://ac.nowcoder.com/acm/contest/11259/A

题目描述

Ares is the Greek god of courage and war. He is one of the Twelve Olympians and the son of Zeus and Hera. In Greek literature, he often represents the physical or violent and untamed aspect of war and is the personification of sheer brutality and bloodlust, in contrast to his sister, the armored Athena, whose functions as a goddess of intelligence include military strategy and generalship.

A Toilet-Ares appeared at the western hub of the mysterious East. They took part in ShengJing AUPC(abnormal university programming competition). There are n problems in this competition. For some irresistible reason, the Toilet-Ares had got solutions to all of the problems. To ensure the fairness of AUPC, the groups of problems' authors changed the problems immediately. They changed n−m problems in total and enhanced data ranges of simple

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
c-ares 是一个 C 语言的异步 DNS 解析库,它可以在 Windows 平台上使用。在 Windows 上,c-ares 使用操作系统提供的 DNS 解析服务,即使用了 Windows 的 DNS Client 服务进行 DNS 解析。 如果你想在 Windows 平台上使用 c-ares 进行 DNS 解析,需要使用 c-ares 的库文件,并在代码中使用 c-ares 的 API 进行 DNS 解析操作。在使用 c-ares 进行 DNS 解析时,需要注意以下几点: 1. 你需要在程序中初始化 c-ares 库,并在程序结束前清理 c-ares 库资源。 2. 在进行 DNS 解析操作时,需要创建一个 c-ares 查询对象(ares_query),并设置回调函数来处理查询结果。 3. c-ares 的回调函数是异步执行的,因此需要在回调函数中进行线程同步操作,以保证程序正确性。 下面是一个使用 c-ares 进行 DNS 解析的示例代码: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ares.h> static void callback(void *arg, int status, int timeouts, struct hostent *host) { if (status == ARES_SUCCESS) { printf("Found address for %s:\n", (char *) arg); for (int i = 0; host->h_addr_list[i]; ++i) { printf("%s\n", inet_ntoa(*(struct in_addr *) host->h_addr_list[i])); } } else { printf("Failed to lookup %s: %s\n", (char *) arg, ares_strerror(status)); } } int main(int argc, char **argv) { ares_channel channel; int status; if (argc != 2) { fprintf(stderr, "Usage: %s <hostname>\n", argv[0]); return 1; } status = ares_library_init(ARES_LIB_INIT_ALL); if (status != ARES_SUCCESS) { fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status)); return 1; } status = ares_init(&channel); if (status != ARES_SUCCESS) { fprintf(stderr, "ares_init: %s\n", ares_strerror(status)); return 1; } ares_query(channel, argv[1], ns_c_in, ns_t_a, callback, argv[1]); ares_free(channel); ares_library_cleanup(); return 0; } ``` 在上面的代码中,我们首先使用 ares_library_init() 函数初始化 c-ares 库,然后使用 ares_init() 函数创建一个 c-ares 查询通道(channel)。接着,我们调用 ares_query() 函数进行 DNS 查询操作。最后,我们使用 ares_free() 函数释放查询通道资源,并使用 ares_library_cleanup() 函数清理 c-ares 库资源。 在回调函数 callback() 中,我们根据查询结果输出查询到的 IP 地址或错误信息。注意,我们在回调函数中使用了互斥锁(mutex)来保证线程同步。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值