ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1226. esreveR redrO

I got WA on the test 2
Posted by Bakhodir Boydedaev 4 Sep 2017 00:42

Here is my code which has been written in java. Please help me. I cannot understand what wrong is. Or some tests you have ?. Thanks.

public class EsreveRredrO_1226 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String s = reader.readLine();
        solve(s);
    }

    public static void solve(String s) {
        String text[];
        text = s.split(" ");
        for (int i = 0; i < text.length; i++) {
            String revers = "";
            String temp;
            for (int j = text[i].length() - 1; j >= 0;  j--) {
                    revers = revers.concat(String.valueOf(text[i].charAt(j)));
            }
            if (revers.charAt(0) == '!' || revers.charAt(0) == ',' || revers.charAt(0) == '.' || revers.charAt(0) == '?'
                    || revers.charAt(0) == ':' || revers.charAt(0) == ' ') {
                temp = revers.substring(1, revers.length());
                revers = temp.concat(String.valueOf(revers.charAt(0)));
            }
            if (i != text.length - 1)
            System.out.print(revers + " ");
            else System.out.print(revers);
        }
    }
}

Edited by author 04.09.2017 00:45
Re: I got WA on the test 2
Posted by Mahilewets Nikita [BSUIR] 4 Sep 2017 09:22
I remember the problem is quite a pain in the ass
I remember in that problem you should pay attention on all symbols

If there is new line \n\r you print so
If just \n you print \n

If there is no EOF you don't print EOF

I have not read your code

I have WA2 for a long time

And those symbols at the end of the line were related to those WA's
Re: I got WA on the test 2
Posted by Mewtwo 31 Oct 2017 23:14
Thanks for your words. I did care each symbol and didn't print any additional character at the end, and got AC. :)