逆波兰式的转换 总是输出中断 求大佬帮忙

程序思路应该是对的 也能正确输入 但是输出时总是中断 输出的部分也是对的 求大佬看看到底是什么问题
#include #include typedef struct Node{ char data; struct Node next;}Node,*pNode;typedef struct Stack{ pNode top;}Stack,*pStack;pStack createStack(){ pStack pstack; pstack=(pStack)malloc(sizeof(Stack)); pstack->top=NULL; return pstack;}void Push(pStack pstack,char c){ pNode p; p=(pNode)malloc(sizeof(Node)); p->data=c; p->next=pstack->top; pstack->top=p;}void Pop(pStack pstack){ pNode p; p=pstack->top; char item; item=pstack->top->data; printf("%c",item); pstack->top=pstack->top->next; free(p);}void deletetop(pStack pstack){ pNode p; p=pstack->top; pstack->top=pstack->top->next; free(p);}int first(char a,char b){ int a1; if(a=='+') { if(b==''||b=='/') a1=0; else if(b=='-') a1=1; } else if(a=='-') { if(b=='*'||b=='/') a1=0; else if(b=='+') a1=1; } else if(a=='*') a1=1; else if(a=='/') a1=1; return a1;}void transfo(pStack pstack){ char c; int a; while((c=getchar())!='\n') { if(c>96&&ctop->data=='+'||pstack->top->data=='-'||pstack->top->data=='*'||pstack->top->data=='/') { a=first(c,pstack->top->data); if(a==0) { while(a==0) { Pop(pstack); } Push(pstack,c); } else if(a==1) { Push(pstack,c); } } else if(pstack->top->data=='(') Push(pstack,c); else if(pstack->top==NULL) Push(pstack,c); } else if(c=='(') { Push(pstack,c); } else if(c==')') { while(pstack->top->data!='(') { Pop(pstack); } // if(pstack->top->data=='(') deletetop(pstack); } } while(pstack->top!=NULL) { Pop(pstack); }}int main(){ pStack pstack; pstack=createStack(); transfo(pstack); return 0;}

0

1个回答

应该有个插入代码片的功能,你这代码换行都没有,谁愿意看……

0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
大佬求帮忙
求帮忙 ![在这里插入图片描述](https://img-blog.csdnimg.cn/2018112615060233.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzgwNDcyMQ==,size_16,col...
求大佬帮忙
匿名上位机写了校验码程序,但为什么每次写入飞控时显示校验码超时
求大佬帮忙看一下
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: Error updating database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionExcep...
求大佬帮忙!!!
void modify(char* stuid,char*name,int num)rn rn rn if( !checkAdd(stuid))rn printf("请选择修改项目:1—学号;2—姓名;3—成绩");rn scanf("%d",&p);rn switch(p)rn rn case 2:rn printf("请输入新名字");rn scanf("%s",Newname);rn strcpy(name,Newname);rn printf("成功");rn break;rn rn rnrnrn elseprintf("无信息");rnrnrnrnrnrn这是程序的一部分 rn编译没问题rnstrcpy(name,Newname);rn但是这个改变名字的话不对 不能修改名字 求指教rn
求大佬帮忙~
需求如下:rn表1 rnname ..... rn张三 rn李四rn...rnrn表2rnname 课程rn张三 语文rn张三 数学rn李四 语文rn李四 数学rn李四 英语rnrn想要的效果rn张三 语文,数学rn李四 语文,数学,英语rn...rnrn求各位大佬帮忙~ 感激不尽!
表达式的逆波兰式转换
将一个中缀表达式转换成后缀表达式(逆波兰式),用到了堆栈的数据结构。
逆波兰式转换及求值
实验题目: 表达式求值<br><br>◎实验目的:熟悉栈的用法,并训练应用栈解决实际问题<br><br>◎实验内容:使用键盘输入表达式,计算表达式的值并输出;将表达式转化成后 缀表达式输出,利用后缀表达式求表达式的值并输出。<br>
大佬们,求帮忙
[img=https://img-bbs.csdn.net/upload/201808/30/1535617908_474864.jpg][/img] 这个情况怎么解决啊,求大神们指导,
求大佬帮忙!
[img=https://img-bbs.csdn.net/upload/201806/07/1528383371_744806.png][/img]rn小白求助这几个BUG怎么修复,顺便附上源代码。rnstring grammar = "FA[*+X][-/&X][/%X]B";//文法 rnvoid Grammar::Iteration() rn string temprule = grammar;rn for (int i = 1; i <= level; i++)rn rn int curlen = temprule.length();rn int j = 0;rn while (j < curlen)rn rn if (temprule[j] == 'X')//迭代,替换成文法模型rn rn rule += grammar;rn j++;rn rn else //保留转角rn rn rule += temprule[j];rn j++;rn rn rn temprule = rule;rn rule.clear();rn rn rule = temprule;//迭代好之后的文法规则rnrnvector trunks; // 所有分支rnvector leaves;//所有叶子结点rnvoid LSystem::generateFractal() // 利用加载过的文法,创建分形树rnrn trunks.clear();rn leaves.clear();rn curState.pos = Node(0, 0, 0);rn curState.dir = Node(0, 1, 0);rnrn State stack[3000]; // 状态栈rn for (int i = 0; i <3000; i++)rn rn stack[i].pos.x = 0.0;rn stack[i].pos.y = 0.0;rn stack[i].pos.z = 0.0;rn stack[i].dir.x = 0.0;rn stack[i].dir.y = 0.0;rn stack[i].dir.z = 0.0;rn rn size_t i = 0;rn while (i
大佬们求帮忙
#includern#includern#includernusing namespace std;rntypedef structrn float data;rn int index;rnElement;rnclass Polynomialrn public:rn void create();rn void print();rn void add(Polynomial &a,Polynomial &b); rn //private:rn vectorPolynomial_vector;rn;rnvoid Polynomial::create()rn int m,i;rn Element p;rn cout<<"输出一元多项式的项数:";rn cin>>m;rn for(i=0;i>p.data>>p.index;rn Polynomial_vector.push_back(p);rn rnrnvoid Polynomial::print()rn vector::iterator iter;rn for(iter=Polynomial_vector.begin();iter!=Polynomial_vector.end();iter++)rn if((*iter).data!=0)rn if((*iter).index==0)rn cout<<(*iter).data<::iterator iter1=a.Polynomial_vector.begin();rn vector::iterator iter2=Polynomial_vector.begin(); rn vector::iterator iter3;rn Element t;rn int temp;rn nomial_vector.end()))rn temp=(*iter1).index;rn iter3=find(Polynomial_vector.begin(),Polynomial_vector.end(),temp);rn if(iter3!=Polynomial_vector.end())rn if((*iter1).data+(*iter2).data!=0)rn t.index=(*iter1).index;rn t.data=(*iter1).data+(*iter2).data;rn b.Polynomial_vector.push_back(t) ;rn iter1++;rn iter2++;rn rn elsern iter1++;rn iter2++;rn rn rn elsern b.Polynomial_vector.push_back((*iter1));rn iter1++;rn rn rn if(iter1!=a.Polynomial_vector.end())rn b.Polynomial_vector.push_back(*iter1++);rn rn if(iter2!=Polynomial_vector.end())rn b.Polynomial_vector.push_back(*iter2++);rn rn rnrnrnbool com(Element e1,Element e2)rn return e1.index
求助!求大佬帮忙
[img=https://img-bbs.csdn.net/upload/201905/27/1558886821_837807.png][/img]rn请问这个错误要怎么修改?
求大佬帮忙看看
错误信息:rnClientAbortException: java.net.SocketException: Software caused connection abort: socket write errorrn at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:358)rn at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:434)rn at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:349)rn at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:381)rn at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:370)rn at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89)rn at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)rn at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282)rn at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)rn at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:135)rn at java.io.OutputStreamWriter.write(OutputStreamWriter.java:220)rn at java.io.Writer.write(Writer.java:157)rn at org.springframework.util.StreamUtils.copy(StreamUtils.java:118)rn at org.springframework.http.converter.StringHttpMessageConverter.writeInternal(StringHttpMessageConverter.java:106)rn at org.springframework.http.converter.StringHttpMessageConverter.writeInternal(StringHttpMessageConverter.java:41)rn at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:227)rn at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:247)rn at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:174)rn at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:81)rn at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:113)rn at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)rn at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)rn at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)rn at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)rn at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)rn at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)rn at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)rn at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Thread.java:745)rnCaused by: java.net.SocketException: Software caused connection abort: socket write errorrn at java.net.SocketOutputStream.socketWrite0(Native Method)rn at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)rn at java.net.SocketOutputStream.write(SocketOutputStream.java:155)rn at org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:764)rn at org.apache.coyote.http11.filters.IdentityOutputFilter.doWrite(IdentityOutputFilter.java:118)rn at org.apache.coyote.http11.InternalOutputBuffer.doWrite(InternalOutputBuffer.java:570)rn at org.apache.coyote.Response.doWrite(Response.java:560)rn at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:353)rn ... 45 morern十一月 16, 2017 4:29:10 下午 org.apache.catalina.core.StandardWrapperValve invokern严重: Servlet.service() for servlet MVC DispatcherServlet threw exceptionrnjava.lang.NullPointerExceptionrn at com.zhwy.exception.MyExceptionHandler.resolveException(MyExceptionHandler.java:54)rn at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1222)rn at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1034)rn at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984)rn at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)rn at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)rn at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)rn at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Thread.java:745)rn
求 中断输出字符串
在c中,怎样调用中断来完成输出,不想用printf。rn谢谢!
逆波兰式的转换与计算(简单)
我们平常书写的表达式:--如2+3*4+4 又称为中缀表达式,我们可以将它转换为后缀表达式 213*+4+ 输入有两行,第一行为逆波兰式的结果,第二行为输入表达式的正确计算结果。逆波兰式中相邻的数字或运算符之间不用输出空格 保证表达式计算的合理性,不需判断除零等情况 表达式的计算遵循同级运算从左向右,先乘除后加减 样例输入: 2+1*3+4 样例输出: 213*+4+ 9   ...
输入表达式 输出逆波兰式
private static Scanner in; public static void main(String[] args) { System.out.println("input"); in = new Scanner(System.in); char flag; String s = in.nextLine(); Stack<Character> s
求大佬帮忙看看这道题,总是出错
题目如下: 统计学生成绩。请定义一个结构体变量StudentType, 该结构体存有学生的 姓名,两门成绩:高数,英语,还有总成绩。将n个学生的姓名和其总成绩按照总成绩从高到低输出,每个学生信息输出占一行。(不会出现总成绩相同的情况) struct StudentType {     //姓名     //高数成绩     //英语成绩     //总成
新手求大佬帮忙看看
刚学C语言,实在没法理解。昨天自己憋了一下午,也没看出什么地方有问题。rn[code=c]#pragma warning(disable:4996)rn#includernint main()rnrn char str1[30], str2[30];rn printf("please enter string:");rn gets(str1);rn printf("which character that begin to copy? ");rn int m;rn scanf("%d", &m);rn void str_c(char x[], char y[], int n);rn str_c(str1, str2, m);rn printf("%s\n", str2);rn return 0;rnrnvoid str_c(char x[], char y[], int n)rnrn int i;rn for (i = n; i != '\0'; i++)rn rn y[i - n] = x[i];rn y[i - n] = '\0';rnrn[/code]rnrnrn后面写的str_c 函数目的是想把字符串x中第n个字符后面的复制到字符串y中去。真的无法理解为什么这么写会运行出错?rn有没有前辈解释一下哪错了?谢谢
求大佬来帮忙看看
eclipse一直报An internal error occurred during: "Computing Git status for repository hp222".Trailing char < > at index 82: C:\Users\hp222\AppData\Roaming\duowan\yy\mainframe\theme\float\star-V1-V6-apng.png
求大佬帮忙做个网页
[img=https://img-bbs.csdn.net/upload/201805/18/1526627276_320109.jpg][/img][img=https://img-bbs.csdn.net/upload/201805/18/1526627288_701578.jpg][/img][img=https://img-bbs.csdn.net/upload/201805/18/1526627298_784614.jpg][/img][img=https://img-bbs.csdn.net/upload/201805/18/1526627304_843611.jpg][/img]做成效果图那样的,在线等,挺急的!!!!
编译原理中逆波兰式的转换算法
编译原理中的中间语言翻译器的构造所使用的将一个表达式转换为逆波兰式的算法实现,我用的是vc++6.0写的,程序挺简单的
表达式计算 - 逆波兰式转换及运算示例
表达式计算 - 逆波兰式转换及运算示例自定义表达式运算中,涉及到三个步骤: 1.关键字析取 2.中序表达式转逆波兰表达式 3.逆波兰表达式运算。 本实现基于C#,可生成对象化的中序表达式和逆波兰表达式,可处理函数,并有规范的函数运算扩展示例。
【数据结构】中缀表达式转换后缀表达式(逆波兰式)
我的第一篇博文就是关于逆波兰式的,现在回头看感觉当时的代码太过混乱(不忍直视),在这里对当时的代码进行一次重构。#include <stdio.h> #include "stack.h" #define MaxSize 30 int Judge(int flag,char operater) { if(flag) switch(operater){ c
求算术表达式值 逆波兰式
利用栈和逆波兰式实现算术表达式求值。程序运行正确。
数据结构--求逆波兰式
数据结构---用C写的求逆波兰式数据结构---用C写的求逆波兰式数据结构---用C写的求逆波兰式
Java 求逆波兰式的值
一,给一个逆波兰式的公式,求出它的值1, 该公式运算符只有^, + ,* 这三个,其中^表示自增的。2,例如输入: 1 1 + 2 ^ * 输出为6;二,程序import java.util.*; //阿里的程序题 public class Test2 { public static void main(String[] agrs) { ArrayList<I
[C++]求表达式的逆波兰式
// ReversePolish2.cpp : 定义控制台应用程序的入口点。 //#include "stdafx.h" #include <cstdlib> #include <iostream> #include <string> #include <stack> using std::cout; using std::cin; using std::endl; using std::stack
字串转换输出?高手帮忙!!!
输入字串:123003abc456010123456(任意长)rn输出文件格式为:rn 0----------------------+---------------------16rn00000:31 32 33 30 30 33 61 62 63 34 35 36 30 31 30 31 123003abc4560101rn00016:32 33 34 35 36 23456rnrn左边记录的是ascii码,右边是字符串。(注意有中文)rn如何实现!谢谢大家帮忙!!
求大佬解决easyX输出字符串的问题
[img=https://img-bbs.csdn.net/upload/201907/18/1563412744_342056.jpg][/img]rnrnrn请问为什么输出后又黑色的框框啊[face]qq:34.gif[/face]
逆波兰式
#include #include using namespace std; int main(void){ stack sta; char s[50]; int i , num, a, b, c, sum; cin >> s; i = 0; while (s[i] != '\0'){  num = s[i] - '0';    if (num >= 0 && num
急求555。。算术表达式的翻译程序设计(LR方法、输出逆波兰式)
小弟刚学编译原理一个月,老师要编这个程序,算术表达式的翻译程序设计(LR方法、输出逆波兰式),搞了一阵子,编不出来。我1号的票,编不出来不让回家,555555,那我就不能回去过年了,求求各位大哥大姐帮帮忙,小弟感激涕零。。。。。。。rn
求一算法(逆波兰式->表达式)
比如有一表达式为:a+c*(b-d/e)rn则它的逆波兰式为:acbde/-*+rn现在我想输入逆波兰式求出它的表达式并输出rn那们同仁可以解决的呀,小弟我不甚感激呀?没有代码也行,只要给出个思路就行了,rn小弟我想了一天多了,但是总是找不到好的办法。
急求!算术表达式的翻译程序(算符优先法,输出逆波兰式)
小弟是新手,大体知道用堆栈实现,但实在能力有限,哪位大侠帮助一下!!
新人求助,求大佬帮忙解决
在用android studio生成app的时候总是闪退eventlog里也没有报错感觉是Mainactivity.java里的结构问题rnjava代码如下rn[code=java]package com.example.administrator.calculate;rnimport android.app.Activity;rnimport android.os.Bundle;rnimport android.view.View;rnimport android.widget.Button;rnimport android.widget.EditText;rnrnpublic class MainActivity extends Activity implements View.OnClickListener rnrn Button btn_0;rn Button btn_1;rn Button btn_2;rn Button btn_3 ;rn Button btn_4 ;rn Button btn_5 ;rn Button btn_6 ;rn Button btn_7 ;rn Button btn_8 ;rn Button btn_9 ;rn Button btn_point ;rn Button btn_clear ;rn Button btn_del ;rn Button btn_pluse ;rn Button btn_minus ;rn Button btn_multiply ;rn Button btn_divide ;rn Button btn_equle ;rn EditText et_input;rn boolean clear_flag;rn @Overridern protected void onCreate(Bundle savedInstanceState) rn super.onCreate(savedInstanceState);rn setContentView(R.layout.activity_main);rn btn_1 = (Button) findViewById(R.id.button13);rn btn_2 = (Button) findViewById(R.id.button14);rn btn_3 = (Button) findViewById(R.id.button15);rn btn_4 = (Button) findViewById(R.id.button9);rn btn_5 = (Button) findViewById(R.id.button10);rn btn_6 = (Button) findViewById(R.id.button11);rn btn_7 = (Button) findViewById(R.id.button5);rn btn_8 = (Button) findViewById(R.id.button6);rn btn_9 = (Button) findViewById(R.id.button7);rn btn_point = (Button) findViewById(R.id.button19);rn btn_clear = (Button) findViewById(R.id.button1);rn btn_del = (Button) findViewById(R.id.button4);rn btn_pluse = (Button) findViewById(R.id.button12);rn btn_minus = (Button) findViewById(R.id.button8);rn btn_multiply = (Button) findViewById(R.id.button3);rn btn_divide = (Button) findViewById(R.id.button2);rn btn_equle = (Button) findViewById(R.id.button20);rn et_input = (EditText) findViewById(R.id.et_input);rnrn btn_0.setOnClickListener(this);rn btn_1.setOnClickListener(this);rn btn_2.setOnClickListener(this);rn btn_3.setOnClickListener(this);rn btn_4.setOnClickListener(this);rn btn_5.setOnClickListener(this);rn btn_6.setOnClickListener(this);rn btn_7.setOnClickListener(this);rn btn_8.setOnClickListener(this);rn btn_9.setOnClickListener(this);rn btn_point.setOnClickListener(this);rn btn_clear.setOnClickListener(this);rn btn_del.setOnClickListener(this);rn btn_pluse.setOnClickListener(this);rn btn_minus.setOnClickListener(this);rn btn_multiply.setOnClickListener(this);rn btn_divide.setOnClickListener(this);rn btn_equle.setOnClickListener(this);rnrn rnrn @Overridern public void onClick(View v) rn String str = et_input.getText().toString();rn switch (v.getId()) rn case R.id.button18:rn case R.id.button13:rn case R.id.button14:rn case R.id.button15:rn case R.id.button9:rn case R.id.button10:rn case R.id.button11:rn case R.id.button5:rn case R.id.button6:rn case R.id.button7:rn case R.id.button19:rn if (clear_flag) rn clear_flag = false;rn str = "";rn et_input.setText("");rn rn et_input.setText(str + ((Button) v).getText());rn break;rn case R.id.button12:rn case R.id.button8:rn case R.id.button3:rn case R.id.button2:rn if (clear_flag) rn clear_flag = false;rn str = "";rn et_input.setText("");rn rn if (str.contains("+") || str.contains("-") || str.contains("*") || str.contains("/")) rn str = str.substring(0, str.indexOf(" "));rn rn et_input.setText(str + " " + ((Button) v).getText() + " ");rn break;rn case R.id.button1:rn if (clear_flag)rn clear_flag = false;rn str = "";rn et_input.setText("");rn break;rn case R.id.button4: //判断是否为空,然后在进行删除rn if (clear_flag) rn clear_flag = false;rn str = "";rn et_input.setText("");rn else if (str != null && !str.equals("")) rn et_input.setText(str.substring(0, str.length() - 1));rn rn break;rn case R.id.button20: //单独运算最后结果rn getResult();//调用下面的方法rn break;rn rn rnrn private void getResult() rn String exp = et_input.getText().toString();rn if (exp == null || exp.equals("")) return;rn //因为没有运算符所以不用运算rn if (!exp.contains(" ")) rn return;rn rn if (clear_flag) rn clear_flag = false;rn return;rn rn clear_flag = true;rn //截取运算符前面的字符串rn String s1 = exp.substring(0, exp.indexOf(" "));rn //截取的运算符rn String op = exp.substring(exp.indexOf(" ") + 1, exp.indexOf(" ") + 2);rn //截取运算符后面的字符串rn String s2 = exp.substring(exp.indexOf(" ") + 3);rn double cnt = 0;rn if (!s1.equals("") && !s2.equals("")) rn double d1 = Double.parseDouble(s1);rn double d2 = Double.parseDouble(s2);rn if (op.equals("+")) rn cnt = d1 + d2;rn rn if (op.equals("-")) rn cnt = d1 - d2;rn rn if (op.equals("*")) rn cnt = d1 * d2;rn rn if (op.equals("/")) rn if (d2 == 0) cnt = 0;rn else cnt = d1 / d2;rn rn if (!s1.contains(".") && !s2.contains(".") && !op.equals("÷")) rn int res = (int) cnt;rn et_input.setText(res + "");rn else rn et_input.setText(cnt + "");rn rn rn //如果s1是空 s2不是空 就执行下一步rn else if (!s1.equals("") && s2.equals("")) rn double d1 = Double.parseDouble(s1);rn if (op.equals("+")) rn cnt = d1;rn rn if (op.equals("-")) rn cnt = d1;rn rn if (op.equals("*")) rn cnt = 0;rn rn if (op.equals("/")) rn cnt = 0;rn rn if (!s1.contains(".")) rn int res = (int) cnt;rn et_input.setText(res + "");rn else rn et_input.setText(cnt + "");rn rn rn //如果s1是空 s2不是空 就执行下一步rn else if (s1.equals("") && !s2.equals("")) rn double d2 = Double.parseDouble(s2);rn if (op.equals("+")) rn cnt = d2;rn rn if (op.equals("-")) rn cnt = 0 - d2;rn rn if (op.equals("*")) rn cnt = 0;rn rn if (op.equals("/")) rn cnt = 0;rn rn if (!s2.contains(".")) rn int res = (int) cnt;rn et_input.setText(res + "");rn else rn et_input.setText(cnt + "");rn rn else rn et_input.setText("");rn rn rnrn[/code]
求大佬帮忙改个马踏棋盘程序啊
[b][color=#FF0000]]现在是输出指定初始位置的结果。我想让他一次输出64个所有初始位置的结果。rn自己加了两层循环 怎么也不行 求大佬解答,本人小白一个 附上程序最好了 谢谢大家[/color][/b]rnrnrn#includern#includernrn#define STACK_INIT_SIZE 100rn#define STACKINCREMENT 10rnrntypedef struct //记录坐标位置rnrn int x;rn int y;rnPosType;rntypedef struct //骑士跳步rnrn PosType seat; rn int di; //标记探索的下一个方向rnSElemType;rntypedef struct//栈的结构体rn rn SElemType *base;rn SElemType *top;rn int stacksize;rnSqStack; rnrnint Init1[8][8] = 0 ;//此棋盘用以记录所走过的路rnint Init2[8][8] = rn 2,3,4,4,4,4,3,2,//初始化棋盘,并标记每个位置所能跳的方向rn 3,4,6,6,6,6,4,3,//例如当为2时,表示下一步只有两个方向可跳rn 4,6,8,8,8,8,6,4,//此棋盘用以记录跳棋步骤rn 4,6,8,8,8,8,6,4,rn 4,6,8,8,8,8,6,4,rn 4,6,8,8,8,8,6,4,rn 3,4,6,6,6,6,4,3,rn 2,3,4,4,4,4,3,2,;rnint HTry1[8] = -2, -1, 1, 2, 2, 1, -1, -2;//跳马的下一步的x位置rnint HTry2[8] = 1, 2, 2, 1, -1, -2, -2, -1;//跳马的下一步的y位置rnrnvoid MarkPrint(PosType pos);//此路不能通过,仍标记为0rnPosType NextPos(PosType curpos,int x);//按顺时针寻找下一个方向rnvoid FootPrint(PosType &curpos,int surstep);//此路能过标记相应的步数rnint Pass(PosType &curpos);//判断此路是否能通过rnint InitStack(SqStack &S);//初始化栈rnvoid DestroyStack(SqStack &S);//销毁栈rnint StackEmpty(SqStack &S);//判断栈是否为空rnint Push(SqStack &S,SElemType e);//入栈rnint Pop(SqStack &S,SElemType &e);//出栈rnvoid print(int curstep);//打印路线rnrnint main()rnrn SqStack S; //栈的结构体rn SElemType e; //标记探索的下一个方向rn PosType Mincurpos,curpos,start; //记录坐标位置rn int curstep; //记录步数rnrn InitStack(S); //初始化栈rn printf("请输入起始位置");rn scanf("%d%d",&start.x,&start.y); //请输入起始位置rn curpos = start; //记录初始坐标位置rn curstep = 1; //记录坐标顺序位置rn dorn if(Pass(curpos)) //判断此路是否能通过rn FootPrint(curpos,curstep); //此路能过标记相应的步数rn e.di = 0; //标记探索的下一个方向rn e.seat= curpos; //记录坐标位置rn Push(S,e); //入栈rn if(curstep == 64) //判断栈满rn print(curstep); //打印路线rn DestroyStack(S); //销毁栈rn return 1;rn rn curpos = NextPos(curpos,e.di); //按顺时针寻找下一个方向rn curstep ++; //步数加一rn rn else rn if(!StackEmpty(S)) //判断栈不为为空rn Pop(S,e); //退栈rn curstep --; //步数减一rn while(e.di == 7 && !StackEmpty(S)) rn MarkPrint(e.seat); //此路不能通过,仍标记为0rn Pop(S,e); //退栈rn curstep --; //步数减一rn rn if(e.di < 7) rn Mincurpos = curpos; //Mincurpos记录上次位置rn e.di ++; //方向加一rn curpos = NextPos(e.seat,e.di); //按顺时针寻找下一个方向rn while(Mincurpos.x == curpos.x && Mincurpos.y == curpos.y && e.di < 7) rn e.di ++; //判断此位置的下一个位置的八个方向的最小值是否相同,若相同则直接跳过rn curpos = NextPos(e.seat,e.di); //按顺时针寻找下一个方向rn rn Push(S,e); //出栈rn curstep ++; //步数加一rnrn rn rn rn while(!StackEmpty(S)); //栈不为空rn DestroyStack(S); //销毁栈rn return 0;rnrnrnvoid print(int curstep) //打印路线rnrn for(int i = 0; i < 8; i++) rn for(int j = 0; j < 8; j++) rn printf("%3d",Init1[i][j]); //打印路线rn printf("\n");rn rn printf("\n");printf("\n");rn getchar();rnrnrnvoid MarkPrint(PosType pos) //此路不能通过,仍标记为0rnrn Init1[pos.x][pos.y] = 0;rnrnrnPosType NextPos(PosType curpos,int x) //寻找下一个位置Init2[8][8]中最小的位置,并且此路没有走过rn //寻找下一个位置Init2[8][8]中最小的位置,并且此路没有走过rn PosType MinCurpos,temp;rnrn MinCurpos.x = -1;rn MinCurpos.y = -1;//置此为最小的方向rn for(;x < 8; x++) rn temp.x = curpos.x + HTry1[x]; //跳马的下一步的x位置rn temp.y = curpos.y + HTry2[x]; //跳马的下一步的y位置rn if(temp.x < 0 || temp.x > 7 || temp.y < 0 || temp.y > 7 || Init1[temp.x][temp.y]) continue;//保证此位置在棋盘中rn if(MinCurpos.x == -1 && MinCurpos.y == -1) //先找到下个位置第一个合法的位置 rn MinCurpos = temp;rn else if( Init2[MinCurpos.x][MinCurpos.y] > Init2[ temp.x][temp.y] )//比较找最小rn MinCurpos= temp;rn rn if(MinCurpos.x == -1 && MinCurpos.y == -1) //如果没有下个位置,返回原来位置rn return curpos;rn return MinCurpos; //如果有下个位置,返回位置rnrnrnvoid FootPrint(PosType &curpos,int curstep) //此路能过标记相应的步数rnrn Init1[curpos.x][curpos.y] = curstep; //此路能过标记相应的步数,将Init1存入步数rnrnrnint Pass(PosType &curpos) //判断此路是否能通过rnrn if(!Init1[curpos.x][curpos.y]) //此路不能通过,return 1,否则返回 0rn return 1;rn else return 0;rnrnrnvoid DestroyStack(SqStack &S) //销毁栈rnrn S.base = S.top; //base=toprn S.stacksize = 0; //size置为0rnrnrnint StackEmpty(SqStack &S) //判断栈满rnrn if(S.base == S.top) rn return 1;rn else return 0;rnrnrnint InitStack(SqStack &S) //初始化栈rn rn S.base = (SElemType*)malloc(STACK_INIT_SIZE * sizeof(SElemType));//将s.base申请跳步类型100个空间rn if(!S.base) return 0; rn S.top = S.base;rn S.stacksize = STACK_INIT_SIZE; //长度给100rn return 1;rnrnrnint Push(SqStack &S,SElemType e) //入栈rnrn if(S.top - S.base >= S.stacksize ) //顶减底等于现在的栈中元素个数rn S.base = (SElemType*)realloc(S.base,(STACK_INIT_SIZE+STACKINCREMENT )*sizeof(SElemType));//对malloc申请的内存进行大小的调整.调整为110 rn if(!S.base) return 0;rn S.top = S.base +S.stacksize; //顶为底加长度rn S.stacksize += STACKINCREMENT; //长度加10rn rn *S.top++ = e;rn return 1;rnrnrnint Pop(SqStack &S,SElemType &e) //出栈 rn rn if(S.top == S.base) return 0;rn e = *--S.top; //e=*--S.toprn return 1;rnrn
python编程题求大佬帮忙
编写一个函数,计算1+1/3+1/5+...+1/99的和
求大佬帮忙,我用的2017
n 1数据处理系统nn 一、软件开发目的nn 该软件主要是使用C语言设计开发数据处理程序,实现对数据的排序、查找、插入、计算、输出等功能。二、数据结构nn 定义一个11*10的二维数组。三、软件功能说明1.生成100个随机数:nn 调用库函数rand()或random ()产生100个随机数,并存储在二维数组中的前十行。2.选择法排序:nn 用选择法将数据由小到大排序输出,保存在数组中,按行优先的原则存放(将小数先存满第一行,然后第二行...3.冒泡法排序:nn 用冒泡法将数据由小到大排序输出,保存在数组中,按行优先的原则存放(将小数先存满第-行,然后第二行...4.插入法排序:nn 用插入法将数据由小到大排序输出,保存在数组中,按行优先的原则存放(将小数先存满第一行,然后第二...)..5.查找数据:nn 输入待查找数据,在二维数组中逐个查找,若找到输出数据所在位置的行列号,若无该数值则输出”无此数”。6.转换二进制:nn 将数组中数据转换为二进制并转存到另-数组中输出。7.转换为素数之和:nn 对于原数组中的数进行判断:若为偶数,则表示成两个素数的和,并输出。8.插入数据:nn 输入一个数,将该数插入原数组中,使数组中的数仍然按从小到大排序,将数组中数据按从小到大顺序输出。9.删除数据nn 输入一个数,若原数组中存在该数,则删除该数,使数组中的数仍然按从小到大排序,将数组中数据按从小到大顺序输出。10. 退出系统,结束任务。
求大佬帮忙解决一下问题
ajax请求的时候报这个get错误
求大佬帮忙看下slice怎么定义
[img=https://img-bbs.csdn.net/upload/201907/22/1563770721_167689.jpg][/img]rnrn小白一个,不太懂是什么问题,这里是说slice未定义吗?那我该怎么定义它,求大神。我太菜了。rnrn rn rn rn 搜索过滤 rn rn rn rn rn 名字rn 年龄rn 性别rn rn rn item.名字 | bigrn item.年龄rn item.性别rn rn rn rn rnrn
各位大佬,求帮忙,谢谢了
登录系统的时候报这个错误,网上找了好多办法,说是服务未打开,打开试了还是不可以,求解rn[img=https://img-bbs.csdn.net/upload/201903/21/1553130943_551619.png][/img]rnrn[color=#FF0000]“由于目标计算机积极拒绝,无法连接”[/color]rnrnrn求解呀
关于pip版本的问题 求大佬帮忙
目前的版本号是19.0.3 为什么报错的时候说我是10.0.1