|
||||||||||
About C/C++
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 13.1.0 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. 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; } 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. 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:
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 A In order not to get a Compilation Error, you should know some features of the compiler used on the server.
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. 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:
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 (mapSince 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:
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; } |
||||||||||
|