Skip to content
This repository was archived by the owner on Sep 6, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions src/lesson1/task1/Simple.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ fun main(args: Array<String>) {
* Пользователь задает время в часах, минутах и секундах, например, 8:20:35.
* Рассчитать время в секундах, прошедшее с начала суток (30035 в данном случае).
*/
fun seconds(hours: Int, minutes: Int, seconds: Int): Int = TODO()
fun seconds(hours: Int, minutes: Int, seconds: Int): Int {
val x1 = hours * 60 * 60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переменным лучше давать осмысленные имена

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переменным лучше давать осмысленные имена, соответствующие их назначению в коде

val x2 = minutes * 60
return x1 + x2 + seconds
}

/**
* Тривиальная
Expand All @@ -60,7 +64,11 @@ fun seconds(hours: Int, minutes: Int, seconds: Int): Int = TODO()
* Определить длину того же отрезка в метрах (в данном случае 18.98).
* 1 сажень = 3 аршина = 48 вершков, 1 вершок = 4.445 см.
*/
fun lengthInMeters(sagenes: Int, arshins: Int, vershoks: Int): Double = TODO()
fun lengthInMeters(sagenes: Int, arshins: Int, vershoks: Int): Double {
val s=sagenes*48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Форматирование кода должно быть одинаковым везде --- если вы отделяете знаки операций от операндов пробелами, то делайте это везде. Попробуйте отформатировать ваш код при помощи IntelliJ IDEA и в дальнейшем придерживайтесь такого же стиля кодирования.

val a=arshins*16
return (s+a+vershoks)*4.445/100
}

/**
* Тривиальная
Expand All @@ -76,15 +84,21 @@ fun angleInRadian(grad: Int, min: Int, sec: Int): Double = TODO()
* Найти длину отрезка, соединяющего точки на плоскости с координатами (x1, y1) и (x2, y2).
* Например, расстояние между (3, 0) и (0, 4) равно 5
*/
fun trackLength(x1: Double, y1: Double, x2: Double, y2: Double): Double = TODO()
fun trackLength(x1: Double, y1: Double, x2: Double, y2: Double): Double {
val sx=abs(x1-x2)
val sy=abs(y1-y2)
return sqrt(sqr(sx)+sqr(sy))
}

/**
* Простая
*
* Пользователь задает целое число, большее 100 (например, 3801).
* Определить третью цифру справа в этом числе (в данном случае 8).
*/
fun thirdDigit(number: Int): Int = TODO()
fun thirdDigit(number: Int): Int {
return number%1000/100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Функцию с телом в виде одного return expr можно записать как fun foo(...) = expr

}

/**
* Простая
Expand All @@ -93,7 +107,11 @@ fun thirdDigit(number: Int): Int = TODO()
* прибыл на станцию назначения в h2 часов m2 минут того же дня (например в 13:01).
* Определите время поезда в пути в минутах (в данном случае 216).
*/
fun travelMinutes(hoursDepart: Int, minutesDepart: Int, hoursArrive: Int, minutesArrive: Int): Int = TODO()
fun travelMinutes(hoursDepart: Int, minutesDepart: Int, hoursArrive: Int, minutesArrive: Int): Int {
val sDepart=hoursDepart*60+minutesDepart
val sArrive=hoursArrive*60+minutesArrive
return sArrive-sDepart
}

/**
* Простая
Expand All @@ -102,12 +120,17 @@ fun travelMinutes(hoursDepart: Int, minutesDepart: Int, hoursArrive: Int, minute
* Сколько денег будет на счету через 3 года (с учётом сложных процентов)?
* Например, 100 рублей под 10% годовых превратятся в 133.1 рубля
*/
fun accountInThreeYears(initial: Int, percent: Int): Double = TODO()
fun accountInThreeYears(initial: Int, percent: Int): Double = TODO()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В коммитах лучше избегать ненужных изменений, так как они усложняют объединение наборов изменений от разных разработчиков


/**
* Простая
*
* Пользователь задает целое трехзначное число (например, 478).
*Необходимо вывести число, полученное из заданного перестановкой цифр в обратном порядке (например, 874).
*/
fun numberRevert(number: Int): Int = TODO()
fun numberRevert(number: Int): Int {
val x3=number%10
val x2=number/10%10
val x1=number/100
return x3*100+x2*10+x1
}
30 changes: 28 additions & 2 deletions src/lesson2/task1/IfElse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,18 @@ fun ageDescription(age: Int): String = TODO()
*/
fun timeForHalfWay(t1: Double, v1: Double,
t2: Double, v2: Double,
t3: Double, v3: Double): Double = TODO()
t3: Double, v3: Double): Double {
val ps:Double = (t1*v1+t2*v2+t3*v3)/2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Значения постоянно используемых выражений лучше вынести в отдельные переменные

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Система типов Котлина выведет тип переменной автоматически

var t:Double
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно обойтись без этой переменной, если все возвращать сразу

if (t1*v1 < ps)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Форматирование кода

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Данное выражение лучше оформить как when

if (t1*v1+t2*v2 < ps)
{t = t1+t2+(ps-t1*v1-t2*v2)/v3}
else {t = t1+(ps-t1*v1)/v2}
else {t = ps/v1}
return t


}

/**
* Простая
Expand Down Expand Up @@ -89,4 +100,19 @@ fun triangleKind(a: Double, b: Double, c: Double): Int = TODO()
* Найти длину пересечения отрезков AB и CD.
* Если пересечения нет, вернуть -1.
*/
fun segmentLength(a: Int, b: Int, c: Int, d: Int): Int = TODO()
fun segmentLength(a: Int, b: Int, c: Int, d: Int): Int {

if ((c in a..b) && (d in a..b))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Данную цепочку if'ов лучше оформить в виде when

{ return d-c }
else if ((c in a..b) && (d !in a..b))
{return b-c}
else if ((d in a..b) && (c !in a..b))
{return d-a}
else if ((a in c..d) && (b in c..d))
{ return b-a }
else if ((a in c..d) && (b !in c..d))
{return d-a}
else if ((b in c..a) && (a !in c..d))
{return b-c}
else {return -1}
}