Skip to content

Instantly share code, notes, and snippets.

@avamsi
Created February 1, 2015 08:40
Show Gist options
  • Save avamsi/e1248cb1b0816c230ff1 to your computer and use it in GitHub Desktop.
Save avamsi/e1248cb1b0816c230ff1 to your computer and use it in GitHub Desktop.
template <class number>
void input(number *ptr){
register char c = getchar_unlocked();
while (c < 33)
c = getchar_unlocked();
*ptr = 0;
while (c > 33){
*ptr = (*ptr * 10) + (c - '0');
c = getchar_unlocked();
}
}
template <class number>
void print(number n, char end = '\n'){
register char c;
char num[20];
int i = 0;
do{
num[i++] = n%10 + 48;
n /= 10;
} while (n != 0);
i--;
while (i >= 0)
putchar_unlocked(num[i--]);
putchar_unlocked(end);
}
template <class number>
void input(number *ptr){
register char c = getchar_unlocked();
bool sign = false;
while (c < 33)
c = getchar_unlocked();
*ptr = 0;
if (c == '-'){
sign = true;
c = getchar_unlocked();
}
while (c > 33){
*ptr = (*ptr * 10) + (c - '0');
c = getchar_unlocked();
}
if (sign)
*ptr *= -1;
}
template <class number>
void print(number n, char end = '\n'){
register char c;
char num[20];
int i = 0;
bool sign = false;
if (n < 0){
sign = true;
n *= -1;
}
do{
num[i++] = n%10 + 48;
n /= 10;
} while (n != 0);
i--;
if (sign)
putchar_unlocked('-');
while (i >= 0)
putchar_unlocked(num[i--]);
putchar_unlocked(end);
}
void print(const char* format, ...){
va_list arguments;
va_start(arguments, format);
register char c;
char num[20];
int i = 0, j;
long n;
while (format[i] != '\0'){
if (format[i] != '{')
putchar_unlocked(format[i++]);
else{
i += 2;
n = va_arg(arguments, long);
j = 0;
do{
num[j++] = n%10 + 48;
n /= 10;
} while (n != 0);
j--;
while (j >= 0)
putchar_unlocked(num[j--]);
}
}
va_end(arguments);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment