-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add yandex_training_1 study_1/task B
- Loading branch information
1 parent
1ef5844
commit 9dc7b2a
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# B. Треугольник | ||
|
||
Даны три натуральных числа. Возможно ли построить треугольник с такими сторонами. Если это возможно, выведите строку YES, иначе выведите строку NO. | ||
|
||
Треугольник — это три точки, не лежащие на одной прямой. | ||
|
||
## Формат ввода | ||
|
||
Вводятся три натуральных числа. | ||
|
||
## Формат вывода | ||
|
||
Выведите ответ на задачу. YES или NO | ||
|
||
### Пример 1 | ||
|
||
<table><tr> | ||
<td> | ||
3<br> | ||
4<br> | ||
5 | ||
</td> | ||
<td> | ||
YES<br> | ||
<br> | ||
<br> | ||
</td> | ||
</tr></table> | ||
|
||
### Пример 2 | ||
|
||
<table><tr> | ||
<td> | ||
3<br> | ||
5<br> | ||
4 | ||
</td> | ||
<td> | ||
YES<br> | ||
<br> | ||
<br> | ||
</td> | ||
</tr></table> | ||
|
||
### Пример 3 | ||
|
||
<table><tr> | ||
<td> | ||
4<br> | ||
5<br> | ||
3 | ||
</td> | ||
<td> | ||
YES<br> | ||
<br> | ||
<br> | ||
</td> | ||
</tr></table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
func main() { | ||
scanner := bufio.NewScanner(os.Stdin) | ||
|
||
scanner.Scan() | ||
a, _ := strconv.Atoi(scanner.Text()) | ||
|
||
scanner.Scan() | ||
b, _ := strconv.Atoi(scanner.Text()) | ||
|
||
scanner.Scan() | ||
c, _ := strconv.Atoi(scanner.Text()) | ||
|
||
fmt.Println(solution(a, b, c)) | ||
} | ||
|
||
func solution(a, b, c int) string { | ||
if a+b <= c || b+c <= a || a+c <= b { | ||
return "NO" | ||
} | ||
|
||
return "YES" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
type TestItemInput struct { | ||
a, | ||
b, | ||
c int | ||
} | ||
|
||
type TestItemOutput string | ||
|
||
type TestItem struct { | ||
input TestItemInput | ||
output TestItemOutput | ||
} | ||
|
||
func TestTask(t *testing.T) { | ||
for i, v := range generateTasks() { | ||
t.Run(fmt.Sprintf("Test %d", i+1), func(t *testing.T) { | ||
val := solution(v.input.a, v.input.b, v.input.c) | ||
if val != string(v.output) { | ||
t.Errorf("Неверный ответ решения!\nОтвет: \n%s \nВерно: \n%s", val, v.output) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func generateTasks() []TestItem { | ||
return []TestItem{ | ||
{TestItemInput{3, 4, 5}, "YES"}, | ||
{TestItemInput{3, 5, 4}, "YES"}, | ||
{TestItemInput{4, 5, 3}, "YES"}, | ||
{TestItemInput{1, 2, 3}, "NO"}, | ||
} | ||
} |