Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add A2030 #45

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions algorithms-and-data-structures/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("java")
kotlin("jvm")
}

group = "com.xtenzq"
Expand All @@ -12,8 +13,12 @@ repositories {
dependencies {
testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
implementation(kotlin("stdlib-jdk8"))
}

tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(17)
}
8 changes: 8 additions & 0 deletions algorithms-and-data-structures/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
pluginManagement {
plugins {
kotlin("jvm") version "2.0.20"
}
}
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}
rootProject.name = "algorithms-data-structs"

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.xtenzq.codeforces

fun a2030() {
val t = readln().toInt()
for (j in 0..< t) {
val n = readln().toInt()
val a = readln().split(" ").map { it.toInt() }

if (n == 1) {
println(0)
continue
}

println((a.max() - a.min()) * (n - 1))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.xtenzq.codeforces

import com.xtenzq.codeforces.utils.assert
import org.junit.jupiter.api.Test

class A2030KtTest {

@Test
fun `A2030 basic test`() {
val input = "3\n" +
"1\n" +
"69\n" +
"3\n" +
"7 6 5\n" +
"5\n" +
"1 1 1 2 2\n"
val expectedOutput = "0\n" +
"4\n" +
"4\n"

assert(input, expectedOutput, { a2030() })
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.xtenzq.codeforces.utils

import org.junit.jupiter.api.Assertions.assertEquals
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.PrintStream

fun assert(input: String, expectedOutput: String, problem: () -> Unit) {
val inputStream = ByteArrayInputStream(input.toByteArray())
val outputStream = ByteArrayOutputStream()
System.setIn(inputStream)
System.setOut(PrintStream(outputStream))

problem()

assertEquals(expectedOutput, outputStream.toString())
}
Loading