Cause for wrong answer could either be that your logic is wrong, or you have formatting issues. Make sure that the output format is exactly the same as specified in the problem statement. Check for extra/missing whitespaces/newlines/debug output statements. If a few test cases have passed, that probably means some of the other test cases have edge cases that your code is not handling. Think about every possible edge case within the problem specifications (you will never be given invalid input), and handle them.
If you're using Java/Clojure/Scala, please ensure that you follow the appropriate class/package naming guidelines mentioned above. These are essential to get your code to run.