打算学完编译原理后再次实现它。。。

以下为比较“杂乱”的方法:

海量数据: https://pan.baidu.com/s/1Prd0ZqNLoCLLvXyJjCef3w

如果大家有发现这个程序的问题,请联系我,谢谢啦~~~ 我很疑惑,不知道错在哪里,难受。。。

 /*把黏在一起的代码以某种格式进行编排
编排方式:https://pintia.cn/problem-sets/994805046380707840/problems/994805047169236992
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define maxlen 1000000 char str[maxlen],s[maxlen];
long len,i,j,w=,g;
long sum_lock=,lock[maxlen],sum_lockif=,lockif[maxlen];
bool vis=false;
char c=' ',vis_kuo; //' ' ///删除多余的空格
void DelSpace()
{
while (str[i]==' ') //delete ' '
i++;
} ///'{'及换行操作
void EndOfLeft()
{
DelSpace();
if (str[i]=='{')
{
i++;
DelSpace();
///锁定,之后的位置(行首空格)大于等于lock[sum_lock]
sum_lock++;
lock[sum_lock]=w+;
}
printf("{\n");
w++;
for (j=;j<*w;j++)
// printf(" ");
printf("%c",c);
} ///_(condition)_
void Parenthese()
{
DelSpace();
// printf(" ");
printf("%c",c);
///c语言中语句有括号,这是定义,即if () while ();而pascal等语言可以没有
vis=false; g=;
while (!(vis && g==)) //not exit initially
{
printf("%c",str[i]);
if (str[i]=='(')
{
vis=true;
g++;
}
else if (str[i]==')') //the number of ')' is the same as '('
g--;
i++;
}
// printf(" ");
printf("%c",c);
EndOfLeft();
} ///遇到else的操作:上一个if的位置决定空格的情况
void elseOp()
{
while (w>lockif[sum_lockif]-) //-1
{
printf("\n");
w--;
for (j=;j<*w;j++)
// printf(" ");
printf("%c",c);
printf("}");
}
sum_lockif--;
printf("\n");
for (j=;j<*w;j++)
// printf(" ");
printf("%c",c);
// printf("else "); //add a ' '
printf("else%c",c);
i+=;
EndOfLeft();
} ///'}'及换行操作
void EndOfRight()
{
///先把已有的'}'输出
while ()
{
DelSpace();
if (str[i]!='}')
break;
i++;
printf("\n");
if (vis_kuo)
vis_kuo=false;
else
w--;
for (j=;j<*w;j++)
// printf(" ");
printf("%c",c);
printf("}");
sum_lock--; //解除锁定
} ///若接下来的几个字符为"else",不按lock的情况输出
strncpy(s,str+i,);
s[]='\0';
if (strcmp(s,"else")==)
{
elseOp();
return;
} /**
本身有'{'的,锁定'}'的输出,直到遇到对应的'}',才结束锁定
当被锁定时,输出的'}'的位置必须大于锁定的'{'的位置
*/
///输出到上一个'{'所在的空格位置
while (w>lock[sum_lock])
{
printf("\n");
w--;
for (j=;j<*w;j++)
// printf(" ");
printf("%c",c);
printf("}");
} printf("\n");
for (j=;j<*w;j++)
// printf(" ");
printf("%c",c);
} int main()
{
gets(str);
len=strlen(str);
i=;
DelSpace();
for (;i<len;)
{
///strncpy:add '\0'
// strncpy(s,str+i,6);
// s[6]='\0';
// if (strcmp(s,"main()")==0)
// {
// printf("main()\n");
// i+=6;
// EndOfLeft();
// continue;
// } strncpy(s,str+i,);
s[]='\0';
if (strcmp(s,"main(")==)
{
printf("main(");
i+=;
while (str[i]!=')')
{
printf("%c",str[i]);
i++;
}
printf(")\n");
i++;
///由后面的'{'处理,避免int main(){}
// EndOfLeft();
DelSpace();
continue;
} strncpy(s,str+i,);
s[]='\0';
if (strcmp(s,"for")==)
{
printf("for");
i+=;
Parenthese();
continue;
} strncpy(s,str+i,);
s[]='\0';
if (strcmp(s,"while")==)
{
printf("while");
i+=;
Parenthese();
continue;
} strncpy(s,str+i,);
s[]='\0';
if (strcmp(s,"if")==)
{
sum_lockif++; //锁定if,在遇到else之前,则输出的'}'的位置必须大于锁定的if的位置
lockif[sum_lockif]=w+;
printf("if");
i+=;
vis=true;
Parenthese();
vis=false;
continue;
} strncpy(s,str+i,);
s[]='\0';
if (strcmp(s,"else")==)
{
elseOp();
continue;
}
///程序体的'{',除int main,if,for后面附带的'{'之外
if (str[i]=='{')
{
i++;
DelSpace();
printf("{");
sum_lock++;
lock[sum_lock]=w+; ///如果'{'后面接')',即{},则无增' '输出
if (str[i]=='}')
{
vis_kuo=true;
EndOfRight();
continue;
} printf("\n");
w++;
for (j=;j<*w;j++)
printf(" ");
continue;
}
///程序体的'}',除int main,if,for后面附带的'}'之外
if (str[i]=='}')
{
EndOfRight();
continue;
}
if (str[i]==';')
{
printf(";");
i++;
EndOfRight();
continue;
}
printf("%c",str[i]);
i++;
}
return ;
}
/*
int main(){ int a=3; int b=2; int c=1; int d=0;}
*/
/*
int main(){int a=0; if (3>2) printf("Y"); int b=2; }
*/
/*
int main() {if (3>2) { printf("Y"); } return 0;}
*/
/*
int main() {if (3>2) printf("Y"); return 0;}
*/
/*
int main(){if (3>2) {if (4>3) { if (5>3) {int i=3;} }}}
*/
/*
int main(){if (3>2) if (4>3) if (5>3) int i=3;}
*/
/*
int main() {if (3>2) while (3>2) {if (3>2) printf("Y"); if (3>2) printf("Y"); } return 0;}
*/ /*
int main() { if (3>2) if (4>3) if (6>-2) printf("Y\n"); else if (3>2) printf("Y\n"); else printf("N\n"); return 0; }
*/
/*
int main(){if (3>2) while(3>2){if (3>2) return 3; else return 2; }else while(3>2){while(5>3) printf("Y");} return 0;}
*/
/*
int main(){if (3>2) while(3>2)if (3>2) return 3; else return 2; else while(3>2){while(5>3) printf("Y");} return 0;}
*/
/*
int main(){int i=0; if (2<3) {if (3>2) while (i<2) while (i<3) i++; printf("Y"); } return 0; }
*/
/*
int main(){int i=0; if (3>2) while (i<2) while (i<3) i++; else i--; return 0;}
*/
/*
int main(){int i=0; if (3>2) while (i<2) { if (3>2) printf("Y"); else printf("N"); while (i<3) i++;} else i--; return 0;}
*/
/*
int main(){int i=0; if (3>2) while (i<2) while (i<3) if (3>2) printf("Y"); else printf("N"); else i--; return 0;}
*/
/*
int main(){int i=0; if (3>2) i++;else if (3>2) i++;else if (3>2)i++; return 0;}
*/
/*
int main(){ if (3>2) while (3>2) while (4>3) i++; else while (4>3) j--; }
*/ /*
int main(){while (1>3) while (3>2) while (5>3) i++; j--; k++;}
*/
/*
int main(){while (1>3) if (3>2) printf("Y\n"); }
*/
/*
int main(){while (1>3) if (3>2) printf("Y\n"); else printf("N"); }
*/ /*
int main() { return 0; }
*/
/*
int main(){}
*/
/*
int main() { int i=3; {int i=2;} }
*/
/*
int main() { {int i=2;} if (3>2) if (4>3) else 5>3; }
*/
/*
int main() { if (3>2) i++; {int i=2;} {int i=2;} }
*/
/*
int main() { {int i=2;} { {} } {} }
*/
/*
int main() { {int i=2;} { {i=3; {}} {} } }
*/
/*
int main() {{{{}}}}
*/
/*
int main() { for (int i=1;i<=3;i++) for (int j=1;j<=5;j++) k++; }
*/
/*
int main() { for (int i=1;i<=3;i++) while (3>2) if(3>2) printf("Y\n"}
*/
/*
int main() { if (3>2) i++; else j--; for (i=1;i<=5;i++) j++; while (3>2) i-; }
*/
/*
int main() { if (3>2) { i++; } else { j--; } for (i=1;i<=5;i++) { j++; } while (3>2) { i-; } }
*/
/*
int main() { if ( 3>2 ) i++; else if ( 5>3 &2<3) j--; for ( i=1;i<=3;i++ ) i--; while (1>3 ) j--; }
*/
/*
int main() { if ( (3>2) && (4>3 | 3>2) ) i++;}
*/
/*
int main() { if ( if (3>2) i++; ) i++;}
*/

团体程序设计天梯赛L3-019 代码排版(23分)的更多相关文章

  1. 团体程序设计天梯赛(CCCC) L3019 代码排版 方法与编译原理密切相关,只有一个测试点段错误

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  2. PTA|团体程序设计天梯赛-练习题目题解锦集(C/C++)(持续更新中……)

    PTA|团体程序设计天梯赛-练习题目题解锦集(持续更新中) 实现语言:C/C++:      欢迎各位看官交流讨论.指导题解错误:或者分享更快的方法!! 题目链接:https://pintia.cn/ ...

  3. 团体程序设计天梯赛(CCCC) L3021 神坛 的一些错误做法(目前网上的方法没一个是对的) 和 一些想法

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  4. 团体程序设计天梯赛(CCCC) L3015 球队“食物链” 状态压缩

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code #include <cstdio> #include ...

  5. 团体程序设计天梯赛(CCCC) L3014 周游世界 BFS证明

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  6. 团体程序设计天梯赛(CCCC) L3013 非常弹的球 不同思路

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  7. 团体程序设计天梯赛(CCCC) L3012 水果忍者 上凸或下凹的证明

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code #include <cstdio> #include ...

  8. 团体程序设计天梯赛(CCCC) L3009 长城 方法证明

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  9. PTA L2-001 紧急救援-最短路(Dijkstra)多条最短路找最优解并输出路径 团体程序设计天梯赛-练习集

    L2-001 紧急救援 (25 分)   作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两个城市的快 ...

  10. 树状数组+二分答案查询第k大的数 (团体程序设计天梯赛 L3-002. 堆栈)

    前提是数的范围较小 1 数据范围:O(n) 2 查第k大的数i:log(n)(树状数组查询小于等于i的数目)*log(n)(二分找到i) 3 添加:log(n) (树状数组) 4 删除:log(n) ...

随机推荐

  1. python3去除字符串中括号及括号里面的内容

    a = """ <option value="search-alias=arts-crafts-intl-ship">Arts & ...

  2. jsweb常用代码

    <script> $(function (){ $.ajax({ url: 'https://test.com:8080/api/v1/users?query_not_auth=100&a ...

  3. Thunder——Final发布

    视频: https://www.bilibili.com/video/av17008792/   视频播放截图及简要文字介绍: http://www.cnblogs.com/lick468/p/799 ...

  4. Daily Scrumming 2015.10.20(Day 1)

    一.今明两天任务表 Member Today’s Task Tomorrow’s Task 江昊 购买服务器,搭建服务器,配置服务器端用户与权限管理 配置ruby与rails环境 配置mysql与数据 ...

  5. java第三次实验

    北京电子科技学院(BESTI) 实     验    报     告 课程:Java程序设计   班级:1352       姓名:陈实  学号:20135224 成绩:             指导 ...

  6. python service 服务没有及时响应启动或控制请求

    1053错误 代码运行没有问题后,安装服务,然而start 的时候出现错误 1053:服务没有及时响应启动或控制请求(Error 1053: The service did not respond t ...

  7. POJ 2411 Mondriaan's Dream 插头dp

    题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...

  8. “吃神么,买神么”的第一个Sprint计划(第三天)

    “吃神么,买神么”项目Sprint计划 ——5.23  星期六(第三天)立会内容与进度 摘要:今天的立会主要是报告进度以及遇到的困难. 进度:logo正在进行中,其他基本没什么问题.都确定要做出来的大 ...

  9. 小学四则运算结对项目报告【GUI】

    写在前面 这次的结对项目我做了很长时间,感触也很多.在这次项目中我使用了Java GUI作为和用户的交互方式,但是在上Java课的时候我对GUI和事件驱动这里并没有学的多好,可能是当时对编程还没有什么 ...

  10. 微信小程序之Flex布局

    微信小程序页面布局方式采用的是Flex布局.Flex布局,是W3c在2009年提出的一种新的方案,可以简便,完整,响应式的实现各种页面布局.Flex布局提供了元素在容器中的对齐,方向以及顺序,甚至他们 ...