PTMSSNG - code problem

During this July Long Challenge, I faced a very weird issue about this PTMSSNG question. I understood the question very well came up with the solution to the number occurring an odd number of times in each x and y coordinate array. I used the bitwise xor operation to find the number occurring an odd number of times.

Here’s the code in C++

#include <iostream>

using namespace std;

int main()
{
    int T, N;
    long long x, y, xm, ym, len;

    cin >> T;

    while(T-- > 0)
    {
        cin >> N;
        N = 4*N - 1;

        xm = ym = 0L;

        while(N-- > 0)
        {
            cin >> x >> y;
            xm = xm ^ x;
            ym = ym ^ y;
        }

        cout << xm << " " << ym;
    }
    return 0;
}

Result:

Now here’s exactly the same code in JAVA.

import java.util.Scanner;
class Test
{
	public static void main(String[] args)
	{
		int T, N;
		Scanner in = new Scanner(System.in);
		T = in.nextInt();

		while(T-- > 0)
		{
			N = in.nextInt();
			N = 4*N - 1;
			long X = 0;
			long Y = 0;

			while(N-- > 0)
			{
				X =  X ^ in.nextLong();
				Y =  Y ^ in.nextLong();
			}

			System.out.println(X + " " + Y);
		}
	}
}

Result:

Question is why language made a difference here?? Is there some difference between the xor operation between the two languages?

Please help me this was really frustrating.
Thanks!

1 Like

You just forgot the ‘\n’ or endl in your C++ code. It’s nothing about language.

1 Like

You are not printing new line

1 Like

You forgot to add next line at the end of the answer in c++ solution.

1 Like

Ahh…! what a pain!
Thanks, I was really starting to like JAVA more than C++ :slight_smile:

you forgot new line in C++.