Posts Tagged ‘c++’
Several days ago I stumbled upon a problem EXPR2 in SPOJ. The problem could be very easy if this constraint didn’t exist: use only C/C++, Pascal, or Java, and there must not be any semicolons in the source code.
Well, after googling and thinking a little bit, I realized that this problem can be solved easily using C++. The main savior here is the if block construct.
Enjoyed this article? Subscribe to our RSS feed for free!
Everyone 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.
Enjoyed this article? Subscribe to our RSS feed for free!
In 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.
Enjoyed this article? Subscribe to our RSS feed for free!
I think it’s hard for us to implement a complicated algorithm, write down the code once, compile it, run, and get the expected result, in one shot. That rarely happens. Most of us will encounter some minor or major bugs in the code, and spend some time to find out what’s happening and debug. Programmer is a debugger, an old saying tells us.
Enjoyed this article? Subscribe to our RSS feed for free!
Tired of encountering many bugs in your code? Well, that might be caused by your coding habits. Below are some tips on how to write code that is less error-prone than before!
Enjoyed this article? Subscribe to our RSS feed for free!
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.
Enjoyed this article? Subscribe to our RSS feed for free!
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.
Enjoyed this article? Subscribe to our RSS feed for free!