做业:https://edu.cnblogs.com/campus/nenu/SWE2017FALL/homework/997
代码:https://coding.net/u/Dawnfox/p/f4/git/tree/master/code
git地址:https://git.coding.net/Dawnfox/f4.githtml
看题后不要着急编码,将题目中涉及的功能列出来,肯定可能存在的技术难点。功能一/二实际上就是对操做数、操做符进行操做,这里涉及到的就是核心功能“表达式求值”,输入、输出格式处理都不用着急着去解决。表达式的重复性检验目前没有想到咋用代码实现,待定中。其余想法晚上找文档再补充。git
请查看博客【点击】编程
//求表达式值 static public String OpsExp(string[] arr) { arr = arr.Where(s => !string.IsNullOrEmpty(s)).ToArray(); Stack<string> ovs = new Stack<string>();//操做数 Stack<string> ops = new Stack<string>();//操做符 String res = ""; foreach (string str in arr) { if (str.Equals("=")) { while (ops.Count != 0) { if (ovs.Count >= 2) { string firOps = ovs.Pop(); string secOps = ovs.Pop(); string onceOps = ops.Pop(); String[] resOps = OpsAl(secOps, firOps, onceOps); if (IsValid(resOps[0])) { ovs.Push(resOps[1].ToString()); } else { return res; } } } if (ops.Count == 0) { res = ovs.Pop(); break; } } if (Regex.IsMatch(str, ovsArr)) { ovs.Push(str); } else if (opsArr.Contains(str)) { //第一个运算符 if (ops.Count == 0) { ops.Push(str); } else { //遇到左括号 if (str.Equals("(")) { ops.Push(str); } //15/12/24 3:30 by hr // 还须要考虑括号隔两个操做符的状况! //遇到右括号且当前栈顶元素为左括号 //if (str.Equals(")") && ops.Peek().Equals('(')) if (str.Equals(")")) { //还须要考虑括号隔两个操做符的状况! while (!ops.Peek().Equals("(")) { if (ovs.Count >= 2) { string firOps = ovs.Pop(); string secOps = ovs.Pop(); string onceOps = ops.Pop(); String[] resOps = OpsAl(secOps, firOps, onceOps); if (IsValid(resOps[0])) { ovs.Push(resOps[1].ToString()); } else { return res; } } } if (ops.Peek().Equals("(")) { ops.Pop(); } } if ((str.Equals("+") || str.Equals("-") || str.Equals("*") || str.Equals("/"))) { //当前操做符优先级低于操做符栈顶元素优先级 if (!ops.Peek().Equals("(") && Priority(ops.Peek()) >= Priority(str)) { if (ovs.Count >= 2) { string firOps = ovs.Pop(); string secOps = ovs.Pop(); string onceOps = ops.Pop(); String[] resOps = OpsAl(secOps, firOps, onceOps); if (IsValid(resOps[0])) { ovs.Push(resOps[1].ToString()); ops.Push(str); } else { return res; } } } //当前运算符优先级大于运算符栈顶元素优先级 if (!ops.Peek().Equals("(") && Priority(ops.Peek()) < Priority(str)) { ops.Push(str); } if (ops.Peek().Equals("(")) { ops.Push(str); } } } } else { Console.WriteLine("存在不合法数据或符号"); break; } } return res; }
//随机整数 //number 随机数个数,isDuplicated 随机数是否重复(true 重复,false 不重复) static public int[] GetRadomDigits(int number,int minValue, int maxValue, bool isDuplicated) { Random ra = new Random((int)DateTime.Now.Ticks); int[] resNums = new int[number]; int tmpNum = 0, i=0; for (i = 0; i < number; i++) { tmpNum = ra.Next(minValue, maxValue); //检测随机数是否重复 while (resNums.Contains(tmpNum)&&!isDuplicated) { tmpNum = ra.Next(minValue, maxValue); } resNums[i] = tmpNum; } return resNums; }
//写文件 全部 //todo 路径合法性检验 static public void WriteFile(string path, Dictionary<String, String> contents) { FileStream fs = new FileStream(path, FileMode.Append);//若存在指定文件则追加到文件尾 不然新建文件 StreamWriter sw = new StreamWriter(fs); String content = ""; foreach (KeyValuePair<String, String> ele in contents) { content = string.Format("{0,-30}{1,-10}", ele.Key, ele.Value); //格式化输入内容 sw.WriteLine(content); } sw.Flush();//清空缓冲区 //关闭流 sw.Close(); fs.Close(); }
工做地点:东北师范大学传媒软件所。
计算机: Windows 版本 10.0.15063 64位+外接dell显示屏
队友:袁玥
结对编程能有啥感觉呢?我以为我本身不咋滴,然而其余人都以为我还不错。接触福大以及其余学校的同窗,我清楚认识本身的能力还远远不足以被他人看得上。和个人队友结对编程,我能看到她的不足,编程能力、与人沟通,这样的问题一样存在于我本身身上。如何把本身的想法,对于这个小项目如何去作,怎么去作,阐述清楚,对我而言,仍是很难啊。关于合做过程当中存在较长争论的的事件以下:dom