Taking inputs

jw.lab·2021년 12월 21일
0

Pieces Of Codes

목록 보기
4/8

Python

보통 다음의 input() 함수를 통해 input line 을 받아들인다.

input()

하지만 다음의 input() 함수를 새로 정의하면, 다량의 input을 받을 때 사용할 때 시간이 덜 걸린다.

import sys
input = sys.stdin.readline

C

scanf("%d %d\n",&a,&b);

C++

#include<iostream>
// 다음 3줄을 추가한 경우 cin과 scanf를 혼용하면 안된다.
ios::sync_with_stdio(false); 
cin.tie(NULL); 
cout.tie(NULL);

std::cin>>name;
// 보통 scanf 가 cin 보다 더 빠르다.
scanf("%s \n",&name);

// 또한, 출력시 endl 보다는 \n 사용 시 시간이 단축된다.

다른 언어의 input 방식 역시 공부하는 대로 추가할 예정.

Reference

https://www.acmicpc.net/board/view/22716

0개의 댓글