General
2:1
text packing
Using utf16 strings, you can compress prints that output constant strings, or prints that use constant strings as arguments, to take half the characters.
Spoiler
Compressor
#import<cstring>
#import<clocale>
char str[]="STRING";
int i;
int main(){
for(setlocale(LC_ALL, "en_US.UTF-8");i<strlen(str);i+=2)
__builtin_printf("%C",str[i]+(str[i+1]<<8));
}
Decompressor
Note: compared to just printing via __builtin_printf("...")
, the string must be over 13 characters to get a benefit. However, if your print was already of the form __builtin_printf("...%s",...,"...")
, your string only needs to be over 3 characters to get a benefit.
int main(){__builtin_printf("%s",u"...");}
Output
If you are familiar with or translating from C:
__builtin_printf
can be used in place of printf
without including any header
- You can
#import<ios>
to include common C I/O functions.
- If you have several imports, you may be able to replace all of them with
#import<bits/stdc++.h>
, which includes everything listed here.