Hackerrank – Solve me first & second
Obsahujem riešenia obidvoch úvodných problémov na Hackerrank – Solve me first, Solve me second. Stačí si len vybrať programovací jazyk a odovzdať riešenie, všetko ostané je pre nás vytvorené. Obidve riešenia: Solve me first Solve me second Taktiež dostupné tu a tu. Solve me first Scala
1 2 3 4 5 |
object SolveMeFirst { def main(args: Array[String]) { println(io.Source.stdin.getLines().take(2).map(_.toInt).sum) } } |
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import java.util.*; public class SolveMeFirst { static int solveMeFirst(int a, int b) { return a+b; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int a; a = in.nextInt(); int b; b = in.nextInt(); int sum; sum = solveMeFirst(a, b); System.out.println(sum); } } |
Javascript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// function solveMeFirst(a, b) { return a+b; } function main() { // write your code here. // call `readLine()` to read a line. // use console.log() to write to stdout var a = parseInt(readLine()); var b = parseInt(readLine());; var res = solveMeFirst(a, b); console.log(res); } |
Ruby
1 2 3 4 5 6 7 8 |
def solveMeFirst (a, b) return a+b end val1 = gets.to_i val2 = gets.to_i sum = solveMeFirst(val1,val2) print (sum) |
Solve me […]