【问题标题】:I want the output to be printed after i finished entering the entire input, not showing the output for every line i inputted我希望在完成输入整个输入后打印输出,而不是显示我输入的每一行的输出
【发布时间】:2023-02-04 17:27:01
【问题描述】:

所以我是 CodeBlocks 的新手。我想知道我是否可以在输入全部内容后让 CodeBlocks 输出我的代码?因为我的 CodeBlocks 总是显示我输入的每一行的输出,所以有点烦人。对不起,我的英语不好。如果您感到困惑,请检查我提供的图片,谢谢。

The number is my input, but CodeBlocks always show the 'YES' or 'NO'after i input a number of lines I want the output to be like this

无论如何,这是我用来制作该输出的代码。

#include <stdio.h>

int main(void) {
int t, a, b, c;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
    scanf("%d %d %d", &a, &b, &c);
    if (a + b == c || b + c == a || a + c == b) {
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }
}
    return 0;

}

我尝试在 YouTube 和谷歌上搜索任何可能的网站,但仍未找到任何解决方案

【问题讨论】:

  • 我会在指向char 的指针数组中用fgets 读取整行,然后用sscanf 解析它们。

标签: c codeblocks


【解决方案1】:

如果你正在使用代码块进行竞争性编程,我建议使用带有 cph judge 扩展的 vs code,这样你就不必每次都编写输入,它也有助于一次单击运行所有测试用例。

在你的情况下,我认为你应该尝试在一个我认为你不需要的文件中打印输出,所以我建议在代码的最后创建一个输出和打印数组。

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

int main(void) {
    int t, a, b, c;
    scanf("%d", &t);
    char output[t][4];  //New string array which stores each output
    for (int i = 0; i < t; i++) {
        scanf("%d %d %d", &a, &b, &c);
        if (a + b == c || b + c == a || a + c == b) {
            strcpy(out[i],"YES");
        }
        else {
            strcpy(out[i],"NO");
        }
    }
    for(int i=0;i<t;i++) printf("%s
",out[i]); //Print at last so you get output in the last
    return 0;
}

现在你的输出将在每个编译器中最后打印。希望能帮助到你。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-14
    • 1970-01-01
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    • 2012-01-02
    • 2018-05-15
    • 1970-01-01
    相关资源
    最近更新 更多