在我開始我的問題之前,我想聲明幾件事情: - 這不是本網站上已有問題的副本。 然而,在類似的線條上碰到一個問題,我仍然不明白輸入輸出是如何完成的。如在答覆者說,代碼有Codejam通過終端輸入/輸出問題
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);
}
}
三江源
如果性能是您的最終目標,我會推薦''fgetc()'在'scanf()'上的任何一天。 – WhozCraig 2013-04-07 19:24:50
那麼,究竟是不是工作?你的代碼做了什麼以及你期望它做什麼? – svick 2013-04-07 20:05:36
它本質上是一個翻譯。有一個特定的映射,它接受來自文件的輸入並根據映射將輸出寫入文件。這就是它所做的以及我期望它做的,只能通過linux終端。 – pranavsharma 2013-04-07 20:35:34