• <input id="auww4"></input>
• <input id="auww4"><acronym id="auww4"></acronym></input>
• <input id="auww4"><u id="auww4"></u></input>
<object id="auww4"><acronym id="auww4"></acronym></object>
<input id="auww4"><u id="auww4"></u></input>
• F.A.Q
Hand In Hand
Online Acmers
Forum | Discuss
Statistical Charts
Problem Archive
Realtime Judge Status
Authors Ranklist

C/C++/Java Exams
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
Virtual Contests
DIY | Web-DIY beta
Recent Contests
Register new ID

<< Back to F.A.Q
C and C++ programs are compiled on the server by the Microsoft 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86.
GCC and G++ programs are compiled on the server by MinGW 5.1.3 which is a collection of freely available and freely distributable Windows specific header files and import libraries combined with GNU toolsets that allow one to produce native Windows programs that do not rely on any 3rd-party C runtime DLLs.
Q Are there any examples of solving a problem ?
A This is a sample solution for the A + B problem in the C language:
#include <stdio.h>
main()
{
int a, b;
while(scanf("%d%d", &a, &b) != EOF)
printf("%d\n", a + b);
}

And this is a sample solution for the same problem in C++:
#include <iostream>
using namespace std;
int main()
{
int a, b;
while(cin >> a >> b)
cout << a + b << endl;
return 0;
}

Also, you may use the old header file iostream.h, but in this case a part of stream input/output functions will be unavailable.
#include <iostream.h>
int main()
{
int a, b;
while(cin >> a >> b)
cout << a + b << endl;
return 0;
}

Q How to input and output ?
A An example of how to use input/output is given above. C++ programmers may always choose between two input/output libraries: standard (scanf, printf) or stream (cin, cout) input/output. Stream input/output is easy to use, but it works much slower than standard input/output. This may even cause receiving the Time limit exceeded verdict. Therefore, if you see that a problem requires reading a lot of input data (for example, more than a megabyte) or a large output is expected, then you should better use standard input/output.

Remember that symbol reading functions return negative values for symbols with codes 128-255. If input data may contain such symbols, then it is better to transform explicitly the type of the symbol read to unsigned char than to get the Wrong answer or Runtime Error(ACCESS_VIOLATION) verdicts because of this.

Q What's new in the 32-bit compiler compared to the 16-bit one ?
A If you are used to writing programs for old 16-bit DOS compilers (for example, for Borland C++ 3.1), then it would be useful for you to know the following:
• It is allowed to use arrays of size greater than 64 KB.
• The type int is a 32-bit type and coincides with the type long.
• C++ has a new library STL, which makes it essentially easier to develop standard algorithms (see below).
Also, C++ has a lot of new keywords. An attempt to declare a variable with such a name will lead to a Compilation error. Below is the list of new keywords (excepting those starting with "__"):
bool             naked                thread
catch            namespace            throw
const_cast       noinline             true
deprecated       noreturn             try
dllexport        nothrow              typeid
dllimport        novtable             typename
dynamic_cast     property             using
explicit         reinterpret_cast     uuid
false            selectany            wchar_t
mutable          static_cast

Q What are the distinctions of the compiler as compared to other 32-bit C++ compilers ?
A In order not to get a Compilation Error, you should know some features of the compiler used on the server.
• There is no conio.h header file on the server because this file contains functions that are not needed for solving problems.
• It is impossible to use functions from the header file math.h for integer parameters. For example, this code will not be compiled: sqrt(2). It is correct to write sqrt((double)2) or sqrt(2.0).
• The header file math.h contains functions j0, j1, jn, y0, y1, and yn. Therefore, you should not declare global variables with such names if you use math.h.
• The type long double coincides with double. So, sizeof(long double) = sizeof(double) = 8. When solving problems, it is always sufficient to use the type double (unless a special implementation of floating-point numbers is required).
• The function itoa is not supported in GCC/G++. Use the function sprintf.
• The constant M_PI is not supported. You have to define it yourself. For example, use const double PI = acos(-1.0).
• A variable declared in a for statement is accessible only within the body of this statement.
Q How to use 64-bit integer data types ?
A The compiler fully supports 64-bit integers (both signed and unsigned). A signed 64-bit integer ranges from ¨C9223372036854775808 to 9223372036854775807 and an unsigned 64-bit integer ranges from 0 to 18446744073709551615. A 64-bit variable can be declared in two equivalent ways:
__int64 a;
unsigned __int64 b;

long long a;
unsigned long long b;

64-bit variables can be read and written in two ways as well depending on the input/output library used:
#include <stdio.h>
...
scanf("%I64d", &a);
scanf("%I64u", &b);
printf("%I64d", a);
printf("%I64u", b);

#include <iostream>
using namespace std;
...
cin >> a;
cin >> b;
cout << a;
cout << b;

Note that input/output of 64-bit variables is inaccessible if iostream.h is used.
Q What's STL library ?
A The Standard Template Library, or STL, is a C++ library of container classes, algorithms, and iterators; it provides many of the basic algorithms and data structures of computer science, thus helping programmers to shorten their code and to quicken the process of writing a program.

STL containers are ready-made implementations of common data structures. The most useful for solving problems are the following containers:
• a dynamic array vector;
• a sorted associative array map and a sorted set set, which are based on red-black trees (search, insert, and delete operations are performed in logarithmic time);
• queue, priority_queue, deque, and stack.
An iterator in STL is an abstraction that allows to traverse elements of a container. From a programmer's point of view, an iterator is any object that supports the operations of dereferencing a pointer to a current element (*, ->) and moving to the next element (++) (the usual pointer is also an iterator). All STL containers provide iterators for traversing their elements; they are available by calling container_type::iterator.

The most popular STL algorithm is the quicksort sort, which works in time O(N ¡Á log N). There are altogether around 60 algorithms in the library, including the binary search binary_search, the generation of the next permutation of elements next_permutation, the linear search find, and many others.

Let us consider an example of solving a problem using STL. Given a set of lines, it is required to output all differing lines in the lexicographic order and to specify for each line the number of times it occurs in the set.
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main()
{
map<string, int> words;
string word;

while (getline(cin, word))
words[word]++;
for (map::iterator it = words.begin(); it != words.end(); it++)
cout << it->first << " - " << it->second << endl;

return 0;
}

Since operations with the container map are performed in logarithmic time, the complexity of the solution is O(N ¡Á log N), where N is the size of the input data.

Some facts that are useful when using STL on HDU Online Judge:
• In some problems it is impossible to use STL containers because of memory and/or time limits. For example, the standard class set uses three pointers for each element stored in it; sometimes this may be unacceptable.
• It is guaranteed that the implementation of STL on HDU Online Judge complies with the C++ standard. Non-standard extensions of the library (hash_map, rope, slist, and others) may be unaccessible. If you think that some STL features are unavailable here, please write about it in the forum.
Q Any other notes ?
A You must not throw exceptions in solutions of problems (even inside a block try ... catch) - this will be interpreted by the checker as a Runtime Error.

In order to increase the size of a stack and to avoid its overflow when using a ¡°deep¡± recursion, you should use a special directive (in the example, the size of the stack is set to be 16 MB):
#pragma comment(linker, "/STACK:16777216")

It is convenient to use the conditional directive ONLINE_JUDGE for debugging solutions.
#include <stdio.h>
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", a + b);
return 0;
}

Note that the function freopen may also be used with stream input/output.
#include <iostream>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
int a, b;
cin >> a >> b;
cout << a + b << endl;
return 0;
}