Блог пользователя Big_Integer

Автор Big_Integer, история, 8 лет назад, По-английски

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.

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
8 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
8 лет назад, скрыть # |
Rev. 5  
Проголосовать: нравится 0 Проголосовать: не нравится

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.

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      8 лет назад, скрыть # ^ |
      Rev. 9  
      Проголосовать: нравится -10 Проголосовать: не нравится

      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.