c - 通过带有 Codejam 问题的终端进行输入/输出

标签 c file io file-handling

在开始提问之前,我想声明几件事:- 这不是本网站上已有问题的副本。 然而,类似的线上恰好有一个问题,我仍然不明白输入输出是如何完成的。如,回答者说代码有

int main(int argc, int argv**)
{
}

但是,在网站上发布的解决方案中,甚至没有使用它。问题的一个例子是 https://code.google.com/codejam/contest/1460488/dashboard#s=p0&a=0 。 (用方言说话。我确实使用 ubuntu 终端,并尝试按照 How can I do file i/o without fstream for competitions like google code jam? 的指示进行操作。结果发现我的输出文件中没有写入任何内容。我可以更好地指导,如何实现这一点。这不是我所做的家庭作业已经这样了。我只需要知道如何在 Linux 终端中进行输入输出。

我还给出了我的代码:-

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

#define DEBUG 1
#define printd if (DEBUG) printf

char cipher[26] =     {'y', 'h', 'e', 's', 'o', 'c', 'v', 'x', 'd', 'u', 'i', 'g', 'l', 'b', 'k', 'r', 'z', 't', 'n', 'w', 'j', 'p', 'f', 'm', 'a', 'q'};  

int main()
{
  int count, j;
  scanf("%d\n", &count);
  for (j=0;j<count;j++)
  {
    printf("Case #%d: ",j+1);
    translate();
    printf("\n");
  }
}
void translate()
{
  char c;
  scanf("%c", &c);
  while (c != '\n')
  {
    if (c == ' ')
      printf(" ");
    else
    {
      int index = c - 'a';
      if (index >=0 && index <= 26)
      {
        printf("%c", cipher[index]);
      }
    }
    scanf("%c", &c);
  }
}

谢谢。

最佳答案

将文件编译为 foo 后,您可以执行以下操作:

./foo < input > output

这将读取输入并将您使用 printf 编写的所有内容写入输出。

关于c - 通过带有 Codejam 问题的终端进行输入/输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15866613/

相关文章:

git - 我可以限制在 github.com 中上传某些文件扩展名吗?

c# - 当文件夹名称的文件已经存在时,如何创建一个空文件夹?

c - 在 C 语言中向文件追加位

对 stdin、stdout 和 stderr 的工作方式感到困惑

javascript - 如何使用 Nestjs 和 Multer 读取上传的文件 (text/.csv)

java - 在 Java 中限制文件访问

c - 使用gmp编译时出错

c - 使用指针作为函数参数读取并显示姓名和年龄

c++ - 我如何将 uint32_t 转换为 char* 类型

c++ - 动态绑定(bind)或开关/案例?