ACM at Bucknell University
Programming Contest

HomeGeneral Information → C++

Writing code

You may choose to write your code in a standard text editor or in the contest screen.

Using the contest screen

To write code, in the contest window, select your chosen language from the drop down menu at the top right side of the screen. Type your code into the box (ignore the Python 2 code it automatically provides).

Enter test input such as the provided sample input into the box on the mid right side of the screen. Click on the test button to compile and run your code using the test input. You will see results appear in the bottom right box.

To submit code for judging, click on the submit button. Feedback will appear in the bottom right box.

Command line compilation

This is optional but can be done on the campus Linux system. Compile your programs on the terminal command line as follows:

g++ -o Practice Practice.cc

This will produce an executable named Practice.

To run while reading input from the prompt, run your programs on the terminal command line as follows:

Practice < input

input is the name of a file containing your input. The < redirects the contents of the input file into your program as if you were typing them at the prompt. It is not doing file I/O.

C++ Examples of how to read input

Some input will terminate after a known set of values. Some will terminate after reading an unknown amount of input.
// Read in an unknown amount of input and prints the input followed by the sum.
#include <iostream>
using namespace std;
int main() {
    int x;
    int sum = 0;
    while(cin >> x) {
	cout << x << endl;
	sum = sum + x;
    }
    cout << sum << endl;
}


// Read in input until you see a 0 and prints the input followed by the sum.
#include <iostream>
using namespace std;
int main() {
    int x;
    int sum = 0;
    cin >> x;
    while(x != 0) {
	cout << x << endl;
	sum += x;
	cin >> x;
    }
    cout << sum << endl;
}