Help me please :D

Revision en1, by Ahnaf.Shahriar.Asif, 2018-01-30 13:10:50

I saw someone to use a function instead of cin/scanf to input a number;

like that :

int n;
n = in();

where in() function is given bellow :

template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch =getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')break;}return (ng?-n:n);}  ?

i don't know what is faster , i also don't know , how scanf or cin works , can anyone please tell me ????

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Ahnaf.Shahriar.Asif 2018-01-30 13:10:50 573 Initial revision (published)