C++ Contest Code preprocessor
大概可以拿来方便拉模板
变量名、语法都是瞎整的你感觉有用随便用好了..
#include<bits/stdc++.h>
using namespace std;
map<string,int>fp;
inline bool is_space(char c){return c==' '||c=='\t';}
bool Strike(char*t,int len,const char*strpat){
for(int i=0;i<len;++i)
if(t[i]!=strpat[i])
return 0;
return 1;
}
void Copy_File(const char*filename,char*intd){
FILE*inFile=fopen(filename,"r");
char*Line_Buffer=new char[1<<20];
while(!feof(inFile)&&fgets(Line_Buffer,1<<20,inFile)){
// process line
printf("%s%s",intd,Line_Buffer);
}puts("");
}
void Process_File(const char*filename){
int len=strlen(filename);
string filename_string(filename,len);
if(fp[filename])return;
fp[filename]=1;
FILE*inFile=fopen(filename,"r");
char*Line_Buffer=new char[1<<20];
char*Intend_Buffer=new char[1<<20];
while(!feof(inFile)&&fgets(Line_Buffer,1<<20,inFile)){
// process line
int len=strlen(Line_Buffer),int_siz=0,i=0;
for(;i<len;++i)
if(is_space(Line_Buffer[i]))
Intend_Buffer[int_siz++]=Line_Buffer[i];
else break;
if(Strike(Line_Buffer+i,5,"//cp_")){
// cp detected
if(Strike(Line_Buffer+i+5,8,"REQUIRE<")){
int t=i+13,z=0;
while(t<len&&Line_Buffer[t]!='>')++t,++z;
char*FileName=new char[z+2];
memcpy(FileName,Line_Buffer+i+13,z);
FileName[z]=0;
Process_File(FileName);
}else if(Strike(Line_Buffer+i+5,7,"INJECT<")){
int t=i+12,z=0;
while(t<len&&Line_Buffer[t]!='>')++t,++z;
char*FileName=new char[z+2];
memcpy(FileName,Line_Buffer+i+12,z);
FileName[z]=0;
Copy_File(FileName,Intend_Buffer);
}else printf("%s",Line_Buffer);
}else printf("%s",Line_Buffer);
}puts("");
}
int main(int argc,const char**argv){
if(argc<=1)
return puts("Usage: [exec_name] \"FileName\""),0;
Process_File(argv[1]);
// Process_File("cppptest1.cpp");
return 0;
}
C++ Contest Code preprocessor的更多相关文章
- WAVE文件格式解析
WAVE 文件作为Windows多媒体中使用的声音波形文件格式之一,它是以RIFF(Resource Interchange File Format)格式为标准的.这里不针对RIFF文件格式做介绍,不 ...
- HDU 2096 小明A+B(%的运用)
传送门: 小明A+B Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 推荐一篇讲arm架构gcc内联汇编的文章
这是来自ethernut网站的一篇文章,原文链接: http://www.ethernut.de/en/documents/arm-inline-asm.html 另外,据说nut/os是个不错的开源 ...
- YASM User Manual
This document is the user manual for the Yasm assembler. It is intended as both an introduction and ...
- IOCCC(The International Obfuscated C Code Contest)
国际 C 语言混乱代码大赛(IOCCC, The International Obfuscated C Code Contest)是一项国际编程赛事,从 1984 年开始,每年举办一次(1997年.1 ...
- 2015 Multi-University Training Contest 7 hdu 5375 Gray code
Gray code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- DISCO Presents Discovery Channel Code Contest 2020 Qual Task E. Majority of Balls
Not able to solve this problem during the contest (virtual participation). The first observation is ...
- The North American Invitational Programming Contest 2018 E. Prefix Free Code
Consider nn initial strings of lower case letters, where no initial string is a prefix of any other ...
- hdu 3461 Code Lock(并查集)2010 ACM-ICPC Multi-University Training Contest(3)
想不到这还可以用并查集解,不过后来证明确实可以…… 题意也有些难理解—— 给你一个锁,这个所由n个字母组成,然后这个锁有m个区间,每次可以对一个区间进行操作,并且区间中的所有字母要同时操作.每次操作可 ...
随机推荐
- 输入hostname -f提示:hostname: Unknown host
解决方法:将/etc/hosts文件中的内容添加如下所示 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdo ...
- 用正则表达式简单加密(C#为例)
") { List<" }; ") { foreach (char i in key) { keys[counter] = i.ToString(); counte ...
- 新装NGINX重启,出现错误 nginx: [error] open() "/usr/local/nginx/logs/nginx.pid"
重装nginx出现,重启出现错误 ./nginx -s reload nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" ...
- 整合mybatis和spring时 Error creating bean with name 'sqlSessionFactory' defined in class path resource
今天在整合mybatis和spring的时候出的错 报错如下 Exception in thread "main" org.springframework.beans.factor ...
- vue.js 图片预览
Vue.js的图片预览的插件还是不少,但是找了半天还是没找到跟现在项目里能用得很顺手的,其实项目里图片预览功能很简单,点击放大,能双指缩放就可以了.部分vue.js的图片预览库都需要把图片资源单独拿出 ...
- ZendFramework-2.4 源代码 - 开始
ZendFramework 是一种PHP框架. 写在前面 最早遇到ZendFramework是在阅读一款叫Magento电子商务系统源代码时看到,后来因为工作,把注意力侧重在其他方面,就搁置了继续了解 ...
- PHP操作redis的常用例子
Redis常用的例子 1,connect 描述:实例连接到一个Redis. 参数:host: string,port: int 返回值:BOOL 成功返回:TRUE;失败返回:FALSE 示例: &l ...
- SHELL脚本的常规命令
**shell脚本的执行方式: 方法一:首先赋予x权限,再输入相对路径或绝对路径,./testdot.sh或/root/shell/testdot.sh 方法二:sh testdot.sh(会新开一个 ...
- Django配置邮箱登录
1.settings下配置 # AUTH 方法(支持邮箱登录) AUTHENTICATION_BACKENDS = ('users.views.CustomBackend',) 2.views下逻辑如 ...
- Scrapy框架的命令行详解【转】
Scrapy框架的命令行详解 请给作者点赞 --> 原文链接 这篇文章主要是对的scrapy命令行使用的一个介绍 创建爬虫项目 scrapy startproject 项目名例子如下: loca ...