URI Online Judge Solution 1929 - Triangle in C
URI Online Judge | 1929
Triangle
By Guilherme Albuquerque Pinto, Universidade Federal de Juiz de Fora Brazil
Timelimit: 1
Ana and her friends are making a geometry work to school, they need to create various triangles on a chart, with a few sticks of different lengths. Soon they realized that you can not form triangles with three rods of any lengths: if one of the rods is too large relative to the other two, you can't form a triangle.
In this issue, you have to help Ana and her friends to determine if, given the lengths of four rods, it is or not possible to select three rods, among the four, and form a triangle.
Input
The entry consists of one line containing four integers A, B, C and D (1 ≤ A, B, C, D ≤ 100).
Output
Your program should only produce a line containing only one character, which must be 'S' if it is possible to form the triangle or 'N' if you can not form a triangle.
Input Example | Output Example |
6 9 22 15 | S |
14 40 12 60 | N |
URI Online Judge Solution 1929 - Triangle in C
#include <stdio.h> int main(int argc, char const *argv[]) { int i, j, k, v[4]; bool b = false; scanf("%d%d%d%d", &v[0], &v[1], &v[2], &v[3]); for(i = 0; i < 4; i++) for(j = i + 1; j < 4; j++) for(k = j + 1; k < 4; k++) if (v[i] + v[j] > v[k] && v[k] + v[j] > v[i] && v[k] + v[i] > v[j]) b = true; (b) ? puts("S") : puts("N"); return 0; }
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks