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