Big_Integer's blog

By Big_Integer, history, 6 years ago, In English

Hello, I have been trying to solve this problem for some time but getting WA.

The Problem This is a simple task for you.You have to write a simple code that can take three input a, b and c which are the length of the three sides of a Pythagorean triangle and check the triangle is valid or invalid.

The Input

The input file contains several lines. Each line contains three positive integers a, b, c < 100 which indicates the three sides of a triangle. Input is terminated by EOF.

The Output

For each input lines print a comment. Which contains if the triangle is right then “Valid.”, if the triangle is not right then “Invalid.” (Quote for clarification) in a separate line.

Sample Input

6 9 4 13 5 12

Sample Output

Invalid. Valid.

My code

But this approaches are not working out for me. I keep getting WA. I checked both of this code against this triplets and they checked out correctly.

original problem link : http://school.outsbook.com/problems/problemdetails/363

Please provide me some thoughts or error that is causing WA.

Thank you.

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I tried solving it myself and got several WAs too. I would bet on a bug in the checker or that the problem statement is incomplete.

»
6 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

You made a mistake in your code: (a[0]<1||a[0]<1||a[0]<1)

The correct version is (a[0]<1||a[1]<1||a[2]<1)

But I am not sure that this correction gets AC as you sort the array initially

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    the problem says they are all positive so this isn't an issue

»
6 years ago, # |
Rev. 5   Vote: I like it 0 Vote: I do not like it

Both old and new versions output Invalid. to the test case

0 1 1

When the smallest length is zero and both larger numbers are equal, the checker may consider such test case as a valid right triangle, and therefore produces WA verdict to you code.

The following is a slight update to your new version that outputs Valid. to the previous test case.

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int a[3]; const string ans[] = { "Invalid", "Valid" };
    
    while( cin >> a[0] >> a[1] >> a[2] )
        sort( a, a + 3 ),
        cout << ans[ ( a[0] * a[0] + a[1] * a[1] ) == a[2] * a[2] ] << ".\n";
}

Hope that helps.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    He already had the check to discard rectangles with a side smaller than 1. This test is incorrect

    • »
      »
      »
      6 years ago, # ^ |
      Rev. 9   Vote: I like it -10 Vote: I do not like it

      While most sources consider that positive integers to start from 1, and that 0 is a neutral number that is neither positive nor negative, other sources consider that 0 belongs to both positive and negative integers, and that integers starting from 1 are strictly positive numbers.

      The problem statement

      " Each line contains three positive integers a, b, c < 100 which indicates the three sides of a triangle."

      does not mention that the side lengths are strictly positive integers. Furthermore, nothing is mentioned in the problem statement to restrict the two side angles of the right triangle as well as its area to be strictly positive. Therefore, this test case may be what is producing the WA verdict as mentioned before.

      UPDATE: It is not clear what would be wrong with trying to help a high school student in comprehending the possible reason for getting WA verdict, and sharing thoughts as he requested.

      • »
        »
        »
        »
        6 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        No, look at his code: if (a<1 || b<1 || c<1) cout<<"INVALID" He already discarded your test case

        • »
          »
          »
          »
          »
          6 years ago, # ^ |
          Rev. 3   Vote: I like it 0 Vote: I do not like it

          Yes, that's right.

          This statement may be the reason for the WA verdict if the on-line judge considers that any test case

          0 X X

          where X < 100 is a valid right triangle with angles 0, 90, and 90 degrees.

          • »
            »
            »
            »
            »
            »
            6 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Kinda misread the comment. Though, something like that should give Invalid. A triangle's condition is that a + b > c with all triples, and 0 + 90 is not larger than 90

            • »
              »
              »
              »
              »
              »
              »
              6 years ago, # ^ |
              Rev. 6   Vote: I like it 0 Vote: I do not like it

              The mentioned numbers 0, 90, and 90 are the angles of right triangle boundary case. The sum of the three angles of any triangle as you probably know should always be equal to 180 degrees.

              What I am saying is that the on-line judge may be considering the boundary case

              a + b = c

              with a = 0 and b = c = X as a valid right triangle.

              • »
                »
                »
                »
                »
                »
                »
                »
                6 years ago, # ^ |
                  Vote: I like it +10 Vote: I do not like it

                Well the judge is wrong in that case then. Welp, screw you online judge