多重选择函数c语言,大佬在吗,我用C写了一个去多重括号的函数,结果。。。...
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include "malloc.h"
char * changeOrder(char *s);
struct Node
{
char *data;
struct Node * link;
};
struct Node * top1 = NULL;
struct Node * top2 = NULL;
void Push1(char *s)
{
struct Node * temp = (struct Node*) malloc(sizeof(struct Node));
temp->data = s;
temp->link = top1;
top1 = temp;
}
char * Pop1()
{
struct Node * temp;
if (top1 == NULL) return "No element found!";
temp = top1;
char *s = top1->data;
top1 = top1->link;
free(temp);
return s;
}
void Push2(char *s)
{
struct Node * temp = (struct Node*) malloc(sizeof(struct Node));
temp->data = s;
temp->link = top2;
top2 = temp;
}
char * Pop2()
{
struct Node * temp;
if (top2 == NULL) return "No element found!";
temp = top2;
char *s = top2->data;
top2 = top2->link;
free(temp);
return s;
}
//If a command has more than 50 character, or doesn't have ';'
//return 0. Else return 1.
int isLegal(char *s)
{
int smallNumber = 20;
if (strlen(s) < smallNumber) smallNumber = strlen(s);
for (int i = 0; i < smallNumber; i++)
{
if (s[i] == ';')
return 1;
}
return 0;
}
//Read one command form user input.
char *readCommand(char *s, int position)
{
if (isLegal(s) == 0)
{
return "Cannot find ';' in your command or the length"
" of your command is too long, try again!";
}
static char command[20];
int num = 0;
while (s[position] != ';')
{
command[num++] = s[position++];
}
command[num++] = ';';
return command;
}
char * changeOrder(char *s)
{
static char container[100];
int num = 0;
while (num < strlen(s))
{
if (s[num] == '(')
{
Push1("(");
num++;
}
else if (s[num] == ')')
{
while (true)
{
if (Pop1() == "(") break;
Push2(Pop1());
}
while (top2 != NULL)
{
strcat_s(container, Pop2());
}
}
else
{
char *t = readCommand(s, num);
Push1(t);
puts(t);
num += strlen(t);
}
}
while (top1 != NULL)
{
char *t = Pop1();
Push2(t);
}
while (top2 != NULL)
{
strcat_s(container, Pop2());
}
return container;
}
int main()
{
static char buf[] = { "command1;command2;command3;" };
puts(changeOrder(buf));
return 0;
}
多重选择函数c语言,大佬在吗,我用C写了一个去多重括号的函数,结果。。。...相关推荐
- 在C语言的函数后标注small,大佬在吗,我用C写了一个去多重括号的函数,结果。。。...
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include "malloc.h" char * changeOrder(char *s); ...
- c语言多重括号,大佬在吗,我用C写了一个去多重括号的函数,结果。。。
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include "malloc.h" char * changeOrder(char *s); ...
- c语言变量值与数组元素值交换,编写一个交换变量值的函数,利用该函数交换数组a和数组b中的对应元素值。要求尽量用指针的方法实现。数组a...
满意答案 a810693885 推荐于 2016.01.08 采纳率:59% 等级:12 已帮助:5204人 #include void main() { int a[10],b[10]; vo ...
- 用c语言复制程序,怎么用C程序写出一个能复制自己的程序?
发信人: crazywill (开始努力学习啦), 信区: Programming 标 题: 输出为本身的c程序 发信站: 华南网木棉站 (Thu Dec 12 09:41:48 2002), 转信 ...
- c语言万年历输入年月日星期几,菜鸟写的一个万年历(计算输入日期是星期几)...
菜鸟写的一个万年历(计算输入日期是星期几) #include #include int statistic(int a) { int i,t=0; for(i=1;i if(i%4==0) { if( ...
- 在纸上写好一个c语言程序后,上机运行的基本步骤为,c基本概念(选择题).docx
PAGE / NUMPAGES 一.单选题 1.下面叙述中正确的是: (A) 在C语言程序中,main()函数必须放在程序的开始位置 (B) 在C语言程序中,要调用的函数必须在main()函数中定义 ...
- R语言广义线性模型函数GLM、广义线性模型(Generalized linear models)、GLM函数的语法形式、glm模型常用函数、常用连接函数、逻辑回归、泊松回归、系数解读、过散度分析
R语言广义线性模型函数GLM.广义线性模型(Generalized linear models).GLM函数的语法形式.glm模型常用函数.常用连接函数.逻辑回归.泊松回归.系数解读.过散度分析 目录
- R语言使用Rtsne包进行TSNE分析:通过数据类型筛选数值数据、scale函数进行数据标准化缩放、提取TSNE分析结果合并到原dataframe中(tSNE with Rtsne package)
R语言使用Rtsne包进行TSNE分析:通过数据类型筛选数值数据.scale函数进行数据标准化缩放.提取TSNE分析结果合并到原dataframe中(tSNE with Rtsne package) ...
- R语言统计代码运行耗时实战:计算代码运行时间、使用proc.time函数计算代码运行时间
R语言统计代码运行耗时实战:计算代码运行时间.使用proc.time函数计算代码运行时间 目录
最新文章
- Android图片查看支持双击放大缩小、多点触摸(多机型测试,长期使用很稳定)
- Android之文件读写
- 动力环境监控系统论文_浅谈动力环境监控系统技术标准
- matlab求傅里叶级数展开式_傅里叶级数:从向量的角度看函数
- mysql 本地登录失败 - 已授权
- mysql 柱状图统计_js/jquery 进行动态统计 各种柱状图 饼状图 线条图 等
- javascript HTMLElement
- C++类的构造函数、析构函数与赋值函数
- 2021,软件测试的出路在哪里?
- Skyline Web 二次开发- 1.地图显示、Position、AttachEvent
- Cortex-M3 (NXP LPC1788)之EEPROM存储器
- RabbitMQ An unexpected connection driver error occured错误
- 产业分析:中国债券市场投资手册
- 一文看懂开源许可证丨开源知识科普
- WinForm使用Prism和DryIoc实现跨窗体数据绑定
- No 和 Not 的区别
- 昆明计算机ppt培训机构,师友互助实操培训(昆明)ppt课件.ppt
- windows服务器系统时间修改了还是不对
- 携手共赢 人才领航|天河人才港美斯坦福2018IT人才双选会成功举办
- 【编译原理】符号表的实现C语言