题解 | 不要三句号的歪

不要三句号的歪

https://www.nowcoder.com/practice/7cbb7d96fb354f7995d9af1ccf8906b4

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {
    char input[21];
    scanf("%20s", input);

    // 分割字符串
    char *tokens[4];
    int count = 0;
    char *token = strtok(input, ",");
    while (token != NULL && count < 4) {
        tokens[count++] = token;
        token = strtok(NULL, ",");
    }

    // 检查格式是否正确:四部分且第三部分是省略号
    if (count != 4 || strcmp(tokens[2], "...") != 0) {
        return 1; // 输入格式错误,此处假设输入合法,故简化处理
    }

    // 转换为长整型以避免溢出
    long long a = atoll(tokens[0]);
    long long c = atoll(tokens[3]);

    // 计算并输出结果
    printf("%lld\n", c - a - 2);
    return 0;
}

全部评论

相关推荐

ddd7_:跟我一模一样,加微信的hr都同一个,扫码了白年书人查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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