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个区间,每次可以对一个区间进行操作,并且区间中的所有字母要同时操作.每次操作可 ...
随机推荐
- CentOS创建不需要输入密码的sudo用户
linux 怎么让普通用户使用sudo权限不需要输入密码. 在网上看到很多资料,都只说到了在/etc/sudoers添加下列行即可: username ALL=(ALL) ...
- oracle用户创建及权限设置(转)
权限: create session create table unlimited tablespace connect resource dba 例: #sqlplus /nolog SQL> ...
- Vuex的简单了解
vuex的官网了解:https://vuex.vuejs.org/zh/guide/ 一.什么是vuex? Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所 ...
- jquery淡入淡出轮播图
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 两种方法实现text输入框中“请输入关键字”的提醒
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 抽屉head部分,hover应用,鼠标放上变色
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 第9课 文章模块分析及建表 Thinkphp5商城第四季
目录 文章模块的分析 表结构 文章模块的分析 表结构 CREATE TABLE `tp_cate` ( `id` smallint(6) NOT NULL AUTO_INCREMENT COMMENT ...
- 简单聊聊四层/七层模型到HTTP
本文内容借鉴这篇博客:https://blog.csdn.net/agzhchren/article/details/79173491 但是这篇博客也是该博主转载的,文章具体出处我没有找到,如果有人知 ...
- vector函数用法
vector是线性容器,它的元素严格的按照线性序列排序,和动态数组很相似,和数组一样,它的元素存储在一块连续的存储空间中,这也意味着我们不仅可以使用迭代器(iterator)访问元素,还可以使用指针的 ...
- spring-data-mongodb
[引入maven依赖] <!-- mongodb spring --> <dependency> <groupId>org.springframework. ...