Can someone explain this read template ?? I saw it used many coders.....

Правка en1, от Coder_Shubham_24, 2020-12-31 10:17:37

I didn't get logic for these to lines

  1. f |= (ch == '-')
  2. x = (x << 1) + (x << 3) + (ch ^ 48);
template<class T>void read(T& x)
{
	x = 0; int f = 0; char ch = getchar();
	while (ch < '0' || ch>'9') { f |= (ch == '-'); ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
	x = f ? -x : x;
	return;
}
Теги read, #c++ template

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский Coder_Shubham_24 2020-12-31 21:02:40 3
en1 Английский Coder_Shubham_24 2020-12-31 10:17:37 464 Initial revision (published)