C++
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
#include <iostream> | |
int main() | |
{ | |
std::ios_base::sync_with_stdio(false); | |
std::cin.tie(nullptr); | |
while (true) { | |
int n; | |
std::cin >> n; | |
if (n == -1) { | |
break; | |
} | |
solve(n); | |
} | |
return 0; | |
} |
Go
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
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
) | |
var r *bufio.Reader | |
var w *bufio.Writer | |
func init() { | |
r = bufio.NewReader(os.Stdin) | |
w = bufio.NewWriter(os.Stdout) | |
} | |
func main() { | |
defer w.Flush() | |
for { | |
n := 0 | |
fmt.Fscan(r, &n) | |
if n == -1 { | |
break | |
} | |
solve(n) | |
} | |
fmt.Fprintln(w, "End.") | |
} |
Rust
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
use std::io::Write; | |
use std::io::BufRead; | |
fn main() { | |
let stdin = std::io::stdin(); | |
let stdin = stdin.lock(); | |
let mut stdin = std::io::BufReader::new(stdin); | |
let stdout = std::io::stdout(); | |
let stdout = stdout.lock(); | |
let mut stdout = std::io::BufWriter::new(stdout); | |
loop { | |
let mut input = String::new(); | |
stdin.read_line(&mut input).unwrap(); | |
let ab = input.trim() | |
.split_whitespace() | |
.map(|s| s.parse::<i32>().unwrap()). | |
collect::<Vec<i32>>(); | |
if ab[0] + ab[1] == 0 { | |
break; | |
} | |
let result = solve(ab[0], ab[1]); | |
writeln!(stdout, "{result}").unwrap(); | |
} | |
} |
Python
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
import sys | |
N = int(sys.stdin.readline().rstrip()) | |
M = int(sys.stdin.readline().rstrip()) | |
cache = [-1] * 10001 | |
cache[1] = 1 | |
sum = 0 | |
m_prime = 20000 | |
if sum == 0: | |
sys.stdout.write("-1") | |
else: | |
sum = "{}\n".format(sum) | |
m_prime = "{}\n".format(m_prime) | |
sys.stdout.write(sum) | |
sys.stdout.write(m_prime) | |
# 그냥 print 써도 상관 없는 듯. |
Java
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
import java.io.*; | |
import java.util.Arrays; | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | |
final String strN = br.readLine(); | |
final String []strArr = br.readLine().split(" "); | |
final int N = Integer.parseInt(strN); | |
final int[] arr = Arrays.stream(strArr).mapToInt(Integer::parseInt).toArray(); | |
final int result = solve(arr); | |
bw.write(""+result); | |
bw.newLine(); | |
bw.flush(); | |
} | |
} |