I often forget it, so I'll write it down when I look it up.
5
R
R
n <- scan("stdin", quiet = TRUE) #input
cat(n) #output
If quiet = TRUE is not specified, "Read 1 item" will be output when reading, which may be judged as an error message.
Python2
Python2
n = input() #input
print n #output
Python3
Python3
n = int(input()) #input
print(n) #output
Ruby
Ruby
n = gets.to_i #input
puts n #output
C++
C++
#include <iostream>
int main(void){
int n;
std::cin >> n; //input
std::cout << n << std::endl; //output
return 0;
}
It seems that it is better to use cstdio when iostream is slow.
1 2 3
Python3
python3
n = [int(i) for i in input().split()] #input
print(' '.join([str(i) for i in n])) #output
python3
a, b, c = [int(i) for i in input().split()] #input
print(a, b, c) #output
python3
n = list(map(int, input().split()) #input
print(' '.join(map(str, n))) #output
Ruby
Ruby
n = gets.chomp.split.map { |i| i.to_i } #input
puts n.join(' ') #output
Ruby
a, b, c = gets.chomp.split.map { |i| i.to_i } #input
puts "#{a} #{b} #{c}" #output
Recommended Posts