val str = readLine()!! // 读入一行字符串 val n = readLine()!!.toInt() // 一行单个整数 var (n, k) = readLine()!!.split(" ").map{it.toInt()} // 读入一行两个整数 val s = readLine()!!.split(" ") // 字符串列表,List<String>类型 var a = readLine()!!.split(" ").map { it.toInt() } // 整数列表,相当于数组
for (i in1..5) print(i) // 12345 for (i in1 until 5) print(i) // 1234 for (i in5 downTo 1) print(i) // 从5开始反向,54321 for (i in1..5 step 2) print(i) // 从5开始,步长为2,135
funmain(args: Array<String>) { var t: Int = readLine()!!.toInt() while(t-- > 0) { val n = readLine()!!.toInt() val a = readLine()!!.split(" ").map { it.toInt() } val mp = HashMap<Int, Int>() for(i in a.indices) { if(!mp.containsKey(a[i])) mp.put(a[i], 0) mp.put(a[i], mp.get(a[i])!!+1) } var ans: Int = 0 for(i in a.indices) { if(mp.get(a[i]) == 1) { ans = i + 1 break } } println(ans) } }
funmain(args: Array<String>) { val n: Int = readLine()!!.toInt() val s: String = readLine()!! var ans: String = "" var i = 0 var len = 0 while(i < n) { ans += s[i] //ans.plus(s[i]) len++ i += len } println(ans) }
funmain(args: Array<String>) { val n: Int = readLine()!!.toInt() var a = readLine()!!.split(" ").map {it.toInt()} var ans: Int = 0 a = a.sorted() //println(a) for(i in0..n-1 step 2) { ans += a[i+1] - a[i] } println(ans) }