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.
Program-
#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++
#ifndef ONLINE_JUDGE
freopen("fliename.in", "r" , stdin);
freopen("filename.out", "w", stdout);
#endif
Add the file name and you’ll be able to scan the whole file and produce the output in xyz file.in.
Hope this clears your doubt…!!
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.
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!!
@damn_me,are you talking about FB Hacker Cup ?
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…?
Can you specifically answer for JAVA Progrmming Language…??
Great question… Thanks for useful information. Im working with Facebook every day so I
ll use these tips in my work http://supremedissertations.com/.
I don’t have enough karma to ask a question. Guys help me please.
2 Likes
Hmm, if you use some terminal; it’s easy.
g++ -g -o yourexe yourfile.cpp
./yourexe < yourinput.in > youroutput.out
For CMD users; instead of the second line use
yourexe < yourinput.in > youroutput.out
For Java users, using a terminal, you could
java yourclassfile < input.in > 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 java.io
If you do so; you’ll have to change things each time you want things on the standard output.