Input and output in Facebook hacker cup

How to generate output file for given input file in facebook hacker cup
For example -

How to read input from file for below program and output result to file.

#include <iostream>
using namespace std;

int main()
	int t,n;
	cin >> t;
	while (t--)
		cin >> n;
		cout << 2 * n;


As far i know we have to download the input file, so just add this code before scanning any input if you’re using C/C++

freopen("", "r" , stdin);
freopen("filename.out", "w", stdout);

Add the file name and you’ll be able to scan the whole file and produce the output in xyz

Hope this clears your doubt…!! :slight_smile:

IN THAT particular folder.

@rudra_sarraf when you are opening a input file through freopen the output file bydefault gets saved in the same folder.

I’m doing very the same as on CodeChef (and other websites) -

1 Like

If we haven’t add these lines, we’ll get wa verdict? I just forgot adding them, didn’t notice and my all solution got WA as the result!! :frowning:

@damn_me,are you talking about FB Hacker Cup ?

yeah… that only.

in FB Hacker Cup (same as in Google Code Jam) you just need to upload both - source and output, your code is not executed again… So probably there was a problem in your solution…

if you share your input, someone can run his code and return back what was correct output…

Is it necessary for these lines to be present to get your solution accepted on FB Hacker cup…?

No, why do you think so?

Can you specifically answer for JAVA Progrmming Language…??

Great question… Thanks for useful information. Im working with Facebook every day so Ill use these tips in my work

I don’t have enough karma to ask a question. Guys help me please.


Hmm, if you use some terminal; it’s easy.

g++ -g -o yourexe yourfile.cpp
./yourexe < > youroutput.out

For CMD users; instead of the second line use
yourexe < > youroutput.out

For Java users, using a terminal, you could

java yourclassfile < > output.out

For those who wish to use things inside a program, you can use freopen in cstdio; ifstream and ofstream in fstream; for Java you could try BufferedReader and BufferedWriter in

If you do so; you’ll have to change things each time you want things on the standard output.