All about problems in Volume 114. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
lighted
Guru
Posts: 587 Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek
Post
by lighted » Mon Sep 15, 2014 3:20 pm
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
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
LanceHAOH
New poster
Posts: 9 Joined: Tue Aug 27, 2013 9:04 am
Post
by LanceHAOH » Sun Jan 11, 2015 11:05 am
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);
}
}
}
}
Last edited by
brianfry713 on Tue Jan 13, 2015 12:21 am, edited 1 time in total.
Reason: Added code blocks
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Tue Jan 13, 2015 12:21 am
Next time post in the existing thread and use code blocks.
It looks like you figured it out.
Check input and AC output for thousands of problems on
uDebug !
Sabrina Haque
New poster
Posts: 3 Joined: Fri Jan 23, 2015 9:33 am
Post
by Sabrina Haque » Sat Jan 24, 2015 10:24 am
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;
}
Last edited by
brianfry713 on Tue Jan 27, 2015 1:03 am, edited 1 time in total.
Reason: Added code blocks