Archive for the ‘Coding Tricks’ Category

codeEveryone knows that C++ syntax is more flexible than many other languages are. You can type many confusing, tricky, obfuscated, yet working source codes in C++.

But do you know these syntactic tricks? These may only be syntactic sugars, but I find them very useful, especially in contests where speed is important.

Click to read more….

loopIn fact, that task can be easily accomplished using goto statement. You can’t use break statement because it only breaks the innermost loop.

However, many programmers hear the myth that goto statement is very bad, buggy, obsolete, etc. so they want to avoid using it.

So, how to break nested loops in C++, without the mystical GOTO statement? If it were used, the code would be something like this.

Click to read more….

What’s the first sorting algorithm you know?

I’m pretty sure that you have learned some sorting algorithms before. Maybe bubble sort, insertion sort, selection sort, or quicksort. Some of them are easy to code; some are quite tricky.

Sorting is crucial in some tasks. Fortunately sorting is made easier if you’re using C++ language.

Click to read more….

Type conversion often takes place in your programming tasks, especially TopCoder SRMs. That includes conversion from and to string. Unfortunately, C++ doesn’t have built-in string conversion syntax. So we have to define our conversion function. We’ll cover that in this post.

Click to read more….