跳到正文

个人记录

代码加密

破忆约 6 分钟
原文
文章信息与版本

文章信息

发布
2021年11月10日
收录
2025年12月12日
更新
2026年11月19日
篇幅
约 6 分钟
获赞
1

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
char nam[105];
string s,z,b[1000005],e;
char a[1000005],d[1000005];
map<string,int> hsh;
set<string> S;
int tot;
int cnt=0;
bool isA(char x){
	return (x>='a'&&x<='z')||(x>='A'&&x<='Z')||(x>='0'&&x<='9')||x=='_'||x=='.';
}
bool isF(char x){
	return !isA(x);
}
void name(){
	printf("Please enter the program\'s name\n\n");
	scanf("%s",nam);
	freopen("result.cpp","w",stdout);
}
int n;
void cpy(){
	b[++tot]=z;
	n=z.size();
	for(int i=0;i<n;i++) a[i]=z[i];
}
void insert(){
	if(z[0]=='#') return;
	int m=0;
	if(!n) return;
	for(int i=0;i<n;){
		s.clear();
		int j=0;
		if(a[i]==34){
			i++;
			s.push_back(34);
			while(i<n&&a[i]!=34){
				d[m++]=a[i];
				s.push_back(a[i]);
				i++;
			}
			i++;
			s.push_back(34);
			int x=hsh[s];
			if(!x) hsh[s]=++cnt,S.insert(s);
			continue;
		}
		if(a[i]==39){
			i++;
			s.push_back(39);
			while(i<n&&a[i]!=39){
				z[j++]=a[i];
				s.push_back(a[i]);
				i++;
			}
			i++;
			s.push_back(39);
			int x=hsh[s];
			if(!x) hsh[s]=++cnt,S.insert(s);
			continue;
		}
		if(i<n&&a[i]!=34&&a[i]!=39&&!isA(a[i])){
			while(i<n&&a[i]!=34&&a[i]!=39&&!isA(a[i])){
				s.push_back(a[i]);
				int x=hsh[s];
				if(!x) hsh[s]=++cnt,S.insert(s);
				i++;
			}
			int x=hsh[s];
			if(!x) hsh[s]=++cnt,S.insert(s);
			continue;
		}
		while(i<n&&a[i]!=34&&a[i]!=39&&isA(a[i])){
			z[j++]=a[i];
			s.push_back(a[i]);
			i++;
		}
		int x=hsh[s];
		if(!x) hsh[s]=++cnt,S.insert(s);
	}
}
void code(){
	freopen(nam,"r",stdin);
	for(int l=1;getline(cin,z);l++){
		cpy();
		insert();
	}
}
void checkdef(){
	for(int l=1;l<=tot;l++){
		if(b[l][0]=='#') cout<<b[l]<<endl;
		else continue;
	}
}
void ps(int x){
	while(x){
		putchar('a'+x%26);
		x/=26;
	}
	putchar('_');
	putchar(' ');
}
void def(){
	for(set<string,int>::iterator it=S.begin();it!=S.end();++it){
		cout<<"#define ";
		ps(hsh[*it]);
		cout<<*it<<endl;
	}
}
void wl(int l){
	n=b[l].size();
	for(int i=0;i<n;i++) a[i]=b[l][i];
	if(b[l][0]=='#') return;
	if(!n) return;
	for(int i=0;i<n;){
		s.clear();
		int j=0;
		int m=0;
		if(a[i]==34){
			i++;
			s.push_back(34);
			while(i<n&&a[i]!=34){
				d[m++]=a[i];
				s.push_back(a[i]);
				i++;
			}
			i++;
			s.push_back(34);
			ps(hsh[s]);
			continue;
		}
		if(a[i]==39){
			i++;
			s.push_back(39);
			while(i<n&&a[i]!=39){
				z[j++]=a[i];
				s.push_back(a[i]);
				i++;
			}
			i++;
			s.push_back(39);
			ps(hsh[s]);
			continue;
		}
		if(i<n&&a[i]!=34&&a[i]!=39&&!isA(a[i])){
			while(i<n&&a[i]!=34&&a[i]!=39&&!isA(a[i])){
				s.push_back(a[i]);
				int x=hsh[s];
				if(!x) hsh[s]=++cnt,S.insert(s);
				i++;
			}
			ps(hsh[s]);
			continue;
		}
		while(i<n&&a[i]!=34&&a[i]!=39&&isA(a[i])){
			d[m++]=a[i];
			s.push_back(a[i]);
			i++;
		}
		ps(hsh[s]);
	}
}
void write(){
	for(int l=1;l<=tot;l++){
		wl(l);
	}
}
int main(){
	name();
	code();
	checkdef();
	def();
	write();
	return 0;
}
原文