首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

000000c++清理脚本0000000000

后端 7.83MB 26 需要积分: 1
立即下载

资源介绍:

适合c++代码缩短大小
import re type_key = ["int","char","long","short","bool"] _key = ["if","else","const","typedef","swtch","for","while","do","and","or","xor"] mp = {} code = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_" u = 0 def fun(text): stack = [] c = re.compile("//.*") text = re.sub(c, "", text) run = 1 while run: run = 0 for i in range(0, len(text)): if text[i] == "/" and text[i + 1] == "*": stack.append(i) run = 1 elif text[i] == "*" and text[i + 1] == "/": text = text[: stack[-1]] + text[i + 2 :] stack.pop() run = 1 break run = 1 while run: run = 0 for old, new in [ ["\t", ""], [" ", " "], ["\r\n", "\n"], ["\n\n", "\n"], [";;", ";"], [") {", "){"], [")\n{", "){"], ["( )", "()"], ]: while old in text: text = text.replace(old, new) run = 1 for i in "\n;+-*/()&^%<>[]|=,{}!": text = text.replace(f" {i}", i) text = text.replace(f"{i} ", i) return text def _find(m): n = [[[it.group()], it.start(), it.end()] for it in m] cnt = 0 for i in range(1, len(n)): if n[cnt][2] == n[i][1]: n[cnt][0] += n[i][0] n[cnt][2] = n[i][2] else: n[(cnt := cnt + 1)] = n[i] return n[: cnt + 1] def meger1(text, flag): cin = re.compile(f"{flag}[^;]*;\n") m = re.finditer(cin, text) if not m: return text n = _find(m) for u, b, e in n[::-1]: for j in range(0, len(u) - 1): u[j] = u[j].replace(";\n", "") for j in range(1, len(u)): u[j] = u[j].replace(flag, "") con = "".join(u) text = text[:b] + con + text[e:] return text def meger2(text, flag): c = re.compile(f'{flag}[(]"[^"]*?",[^;]*?[)];\n') m = re.finditer(c, text) if not m: return text c = re.compile(f'{flag}[(]"(?P[^"]*?)",(?P[^;]*?)[)];\n') n = _find(m) for i, j, k in n[::-1]: u = [] for item in i: u.append(*re.findall(c, item)) greet = "".join([v[0] for v in u]) orz = ",".join([v[1] for v in u]) con = f'{flag}("{greet}",{orz});\n' text = text[:j] + con + text[k:] return text def meger3(text, flag): c = re.compile(rf"\b(?[a-zA-Z_0-9]+)=(?P[^;]*);\n") if not m: return text n = _find(m) m = [] for i, j, k in n: u = [re.findall(c, it) for it in i] u = [j for i in u for j in i] for i in range(len(u) - 1): if u[i][0] == u[i + 1][0]: u[i] = 0 u = [list(it) for it in u if it] for i in range(len(u) - 1): if u[i + 1][1] == u[i][1]: u[i][1] = u[i + 1][0] elif u[i + 1][1] == u[i][0]: tmp = u[i][1] u[i][1] = u[i + 1][0] u[i + 1][1] = tmp m.append([[[]], j, k]) for i in range(len(u)): m[-1][0][-1].append(u[i][0]) m[-1][0][-1].append(u[i][1]) if i + 1 < len(u): if u[i][1] != u[i + 1][0]: m[-1][0].append([]) for i, j, k in m[::-1]: v = [] for orz in i: cnt = 0 for p in range(len(orz)): if orz[cnt] != orz[p]: orz[(cnt := cnt + 1)] = orz[p] v.append("=".join(orz[: cnt + 1])) v = [f"{i};\n" for i in v] v = "".join(v) text = text[:j] + v + text[k:] return text def merge5(text): pattern = re.compile(r"(\w+)=\1(\+|\-|\*|\/|%|&|\||\^)\s*(\w+);") new_text = re.sub(pattern, r"\1 \2= \3;", text) return new_text def number(x): if x // 53: return number(x // 53) + code[x % 53] return code[x % 53] def replace1(text): global u cnt = [i for i in mp] cnt = sorted(cnt, key=lambda x: len(x) * mp[x], reverse=True) ids = [] for i in cnt: key = number(u) u += 1 for j in re.finditer(rf"\b{i}\b", text): ids.append([key, j.start(), j.end()]) ids = sorted(ids, key=lambda x: -x[1]) for i, j, k in ids: text = text[:j] + i + text[k:] return text def replace2(text): global u c = re.compile("\d*") m = re.finditer(c,text) cnt = [j.group() for j in m] cnt = {j: cnt.count(j) for j in cnt} tot = 1 for i in cnt: key = number(u) u += 1 cod = f"#define {key} {i}\n" p =len(cod) + len(key) * cnt[i] q = len(i)*cnt[i] if p> q: u -= 1 else: text = text.replace(i, key) endl = [i for i in range(len(text)) if text[i] == "\n"] idx = endl[tot] tot += 1 text = text[: idx + 1] + cod + text[idx + 1 :] return text def replace3(text): if "#define rep" in text: return text c = re.compile( r"for\(int (?P\w+)\=(?P[^;]*);(?P=i)<\=(?P[^;]*);(?P=i)\+\+\)" ) m = re.findall(c, text) if not m: return text n = [] idx = 0 for i, a, b in m: cod = f"for(int {i}={a};{i}<={b};{i}++)" idx = text.find(cod, idx) n.append([i, a, b, cod, idx]) idx += 1 sl = sum([len(i) for i in n]) codeing = "#define rep(i,a,b) for(int i=a;i<=b;i++)\n" sv = sum([len(f"rep({i},{a},{b})") for i, a, b in m]) if sl < len(codeing) + sv: for i, a, b, cod, idx in n[::-1]: code = f"rep({i},{a},{b})" text = text[:idx] + code + text[idx + len(cod) :] b = [i for i in range(len(text)) if text[i] == "\n"] text = text[: b[1] + 1] + codeing + text[b[1] + 1 :] return text def replace4(text): if "#define lep" in text: return text c = re.compile( r"for\(int (?P\w+)\=(?P[^;]*);(?P=i)>\=(?P[^;]*);(?P=i)\-\-\)" ) m = re.findall(c, text) if not m: return text n = [] idx = 0 for i, a, b in m: cod = f"for(int {i}={a};{i}>={b};{i}--)" idx = text.find(cod, idx) n.append([i, a, b, cod, idx]) idx += 1 sl = sum([len(cod) for _, _, _, cod, _ in n]) codeing = "#define lep(i,a,b) for(int i=a;i>=b;i--)\n" sv = sum([len(f"lep({i},{a},{b})") for i, a, b in m]) if sl > len(code) + sv: for i, a, b, cod, idx in n[::-1]: code = f"lep({i},{a},{b})" text = text[:idx] + code + text[idx + len(cod) :] b = [i for i in range(len(text)) if text[i] == "\n"] text = text[: b[1] + 1] + codeing + text[b[1] + 1 :] return text def replac

资源文件列表:

main.zip 大约有3个文件
  1. main.exe 8.05MB
  2. main.py 876B
  3. build.py 9.59KB
0评论
提交 加载更多评论
其他资源
基于深度强化学习的dqn和基准p-learning的边缘计算计算卸载方法总结
基于深度强化学习的dqn和基准p-learning的边缘计算计算卸载方法总结
launch4j安装包,3.50版本,window
launch4j 将jar包转换为exe文件,方便执行 Launch4j 是一个开源的可执行文件打包工具,可以将Java应用程序打包成一个独立的EXE文件。它提供了一个图形化界面和命令行接口,是非常方便易用的
C盘优化清理降低磁盘空间不足工具
本安装包是专为解决C盘空间不足、系统性能下降等问题而设计。通过智能扫描并清理垃圾文件、临时文件、无用程序和注册表冗余项等,有效释放C盘空间,优化系统环境。同时,该工具还具备一键清理功能,让操作更加简便快捷,是提升计算机性能、保持系统流畅运行的必备利器。无论是日常办公还是游戏娱乐,都能享受到更加高效稳定的电脑使用体验。还有一些其它的功能供你选择
Excel 和 Zip 的导出 & 上传
Excel 和 Zip 的导出 & 上传
武汉理工大学 实训基于verilog的倒计时
武汉理工大学 实训基于verilog的倒计时
Rancher启动hadoop镜像的必要静态文件
Rancher启动的必要静态文件
python安装包-python程序必备
python-3.10.11,python-3.9.7,python-3.8.7 三个版本都可以安装,就是发布的年限不同,使用功能基本一致。装任意一个均可。解压后点击你所需要的版本安装程序,按照步骤进行安装,为了在python程序中正常运行,需要在安装完毕后配置环境变量,不是安装好就能使用
Navicat连接oracle
本资源用于Navicat连接oracle 备注:仅供学习使用,请下载后24h内删除