Page 4 of 4
Re: 11479 - Is this the easiest problem?
Posted: Mon Sep 15, 2014 3:20 pm
by lighted
Try input in this thread first.
lnr wrote:Can anyone give some special input output?
input:
output:
Accepted.
sohel wrote:A triangle is invalid if any side_length <= 0 or (sum of smaller 2 sides <= largest side).
A triangle is scalene if it is valid && all the sides are distinct.
renatov wrote:To check if the sides form a triangle, you should performe 2 tests:
1. See if every input is greater than zero
2. | b - c | < a < b + c
I got accepted and I didn't check if input is negative. Maybe judge doesn't contain negative input
11479 - WA
Posted: Sun Jan 11, 2015 11:05 am
by LanceHAOH
I have researched this forums for possible hints to why my code is wrong. But I cannot find any. Could someone please help me?
Code: Select all
class Main {
public static void main(String[] args) {
java.util.Scanner in = new java.util.Scanner(System.in);
long[] sides = new long[3];
long cases = in.nextLong();
String triangleType;
for (int i = 1; i <= cases; i++) {
sides[0] = in.nextLong();
sides[1] = in.nextLong();
sides[2] = in.nextLong();
triangleType = "Invalid";
/* Ensure sum of any two sides > third side */
if (sides[0] > 0 && sides[1] > 0 && sides[2] > 0) {
if (sides[0] + sides[1] > sides[2] && sides[1] + sides[2] > sides[0]
&& sides[0] + sides[2] > sides[1]) {
if (sides[0] == sides[1] && sides[1] == sides[2]) {
/* Check for equilateral triangle */
triangleType = "Equilateral";
} else if (sides[0] != sides[1] && sides[0] != sides[2] && sides[1] != sides[2]) {
/* Check for scalene triangle */
triangleType = "Scalene";
} else {
/* Check for isoceles triangle */
triangleType = "Isosceles";
}
}
System.out.println("Case " + i + ": " + triangleType);
}
}
}
}
Re: 11479 - Is this the easiest problem?
Posted: Tue Jan 13, 2015 12:21 am
by brianfry713
Next time post in the existing thread and use code blocks.
It looks like you figured it out.
Re: 11479 - Is this the easiest problem?
Posted: Sat Jan 24, 2015 10:24 am
by Sabrina Haque
got WA
Code: Select all
#include<stdio.h>
int main()
{
int test_case,i;
long long int a,b,c;
scanf("%d",&test_case);
for(i=1;i<=test_case;i++)
{
scanf("%llu %llu %llu",&a,&b,&c);
if(a>=b+c || b>=a+c || c>=a+b || a<=0 || b<=0 || c<=0)
printf("case %d: Invalid\n",i);
else if(a==b && b==c)
printf("case %d: Equilateral\n",i);
else if(a==b || a==c || b==c || c==a)
printf("case %d: Isosceles\n",i);
else if(a!=b && b!=c)
printf("case %d: Scalene\n",i);
}
return 0;
}