Skip to content

Instantly share code, notes, and snippets.

@fjzzq2002
Last active October 23, 2016 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjzzq2002/23e38d72f99091d1289b636d9e085851 to your computer and use it in GitHub Desktop.
Save fjzzq2002/23e38d72f99091d1289b636d9e085851 to your computer and use it in GitHub Desktop.
Quine It

Quine it

put quineit.cpp & quine_base.cpp in the same folder

compile quineit.cpp

call quineit [cppfile]

call macro QUINE when need to QUINE

//Quine
#include <stdio.h>
#include <stdlib.h>
void __quine()
{
printf("const unsigned char __data[]={");
for(int i=0;i<sizeof(__data);i++) printf("%0#4x,",__data[i]);
printf("};\n\n");
for(int i=0;i<sizeof(__data);i++) putchar(__data[i]);
exit(0);
}
#define QUINE __quine()
//By zzq
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <set>
#include <map>
using namespace std;
char sx[233333];
int ps=0;
int main(int argc,char** argv)
{
if(argc!=2)
{
cout<<"Call it with a file name!\n";
return 0;
}
freopen("quine_base.cpp","r",stdin);
while((sx[ps]=getchar())!=-1) ++ps;
freopen(argv[1],"r",stdin);
while((sx[ps]=getchar())!=-1) ++ps;
sx[ps]=0;
fclose(stdin);
freopen(((string)argv[1]+".quine.cpp").c_str(),"w",stdout);
printf("const unsigned char __data[]={");
for(int i=0;i<ps;i++) printf("%0#4x,",sx[i]);
printf("};\n\n%s",sx);
fclose(stdout);
}
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <set>
#include <map>
using namespace std;
int main()
{
int a,b;
if(!(cin>>a>>b)) QUINE;
cout<<a+b<<"\n";
}
const unsigned char __data[]={0x2f,0x2f,0x51,0x75,0x69,0x6e,0x65,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x74,0x64,0x69,0x6f,0x2e,0x68,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x74,0x64,0x6c,0x69,0x62,0x2e,0x68,0x3e,0x0a,0x76,0x6f,0x69,0x64,0x20,0x5f,0x5f,0x71,0x75,0x69,0x6e,0x65,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x70,0x72,0x69,0x6e,0x74,0x66,0x28,0x22,0x63,0x6f,0x6e,0x73,0x74,0x20,0x75,0x6e,0x73,0x69,0x67,0x6e,0x65,0x64,0x20,0x63,0x68,0x61,0x72,0x20,0x5f,0x5f,0x64,0x61,0x74,0x61,0x5b,0x5d,0x3d,0x7b,0x22,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x28,0x69,0x6e,0x74,0x20,0x69,0x3d,0x30,0x3b,0x69,0x3c,0x73,0x69,0x7a,0x65,0x6f,0x66,0x28,0x5f,0x5f,0x64,0x61,0x74,0x61,0x29,0x3b,0x69,0x2b,0x2b,0x29,0x20,0x70,0x72,0x69,0x6e,0x74,0x66,0x28,0x22,0x25,0x30,0x23,0x34,0x78,0x2c,0x22,0x2c,0x5f,0x5f,0x64,0x61,0x74,0x61,0x5b,0x69,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x72,0x69,0x6e,0x74,0x66,0x28,0x22,0x7d,0x3b,0x5c,0x6e,0x5c,0x6e,0x22,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x28,0x69,0x6e,0x74,0x20,0x69,0x3d,0x30,0x3b,0x69,0x3c,0x73,0x69,0x7a,0x65,0x6f,0x66,0x28,0x5f,0x5f,0x64,0x61,0x74,0x61,0x29,0x3b,0x69,0x2b,0x2b,0x29,0x20,0x70,0x75,0x74,0x63,0x68,0x61,0x72,0x28,0x5f,0x5f,0x64,0x61,0x74,0x61,0x5b,0x69,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x65,0x78,0x69,0x74,0x28,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x23,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x51,0x55,0x49,0x4e,0x45,0x20,0x5f,0x5f,0x71,0x75,0x69,0x6e,0x65,0x28,0x29,0x0a,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x69,0x6f,0x73,0x74,0x72,0x65,0x61,0x6d,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x74,0x64,0x69,0x6f,0x2e,0x68,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x74,0x64,0x6c,0x69,0x62,0x2e,0x68,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x61,0x6c,0x67,0x6f,0x72,0x69,0x74,0x68,0x6d,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x74,0x72,0x69,0x6e,0x67,0x2e,0x68,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x61,0x74,0x68,0x2e,0x68,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x73,0x65,0x74,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x61,0x70,0x3e,0x0a,0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,0x73,0x74,0x64,0x3b,0x0a,0x69,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x09,0x69,0x6e,0x74,0x20,0x61,0x2c,0x62,0x3b,0x0a,0x09,0x69,0x66,0x28,0x21,0x28,0x63,0x69,0x6e,0x3e,0x3e,0x61,0x3e,0x3e,0x62,0x29,0x29,0x20,0x51,0x55,0x49,0x4e,0x45,0x3b,0x0a,0x09,0x63,0x6f,0x75,0x74,0x3c,0x3c,0x61,0x2b,0x62,0x3c,0x3c,0x22,0x5c,0x6e,0x22,0x3b,0x0a,0x7d,0x0a,0x0a,};
//Quine
#include <stdio.h>
#include <stdlib.h>
void __quine()
{
printf("const unsigned char __data[]={");
for(int i=0;i<sizeof(__data);i++) printf("%0#4x,",__data[i]);
printf("};\n\n");
for(int i=0;i<sizeof(__data);i++) putchar(__data[i]);
exit(0);
}
#define QUINE __quine()
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <set>
#include <map>
using namespace std;
int main()
{
int a,b;
if(!(cin>>a>>b)) QUINE;
cout<<a+b<<"\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment