以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 趣味2022 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=174253) |
-- 作者:采菊东篱下 -- 发布时间:2022/1/7 14:22:00 -- 趣味2022 用11,12,...,19各一次,写一个表达式(可以出现加减乘除和括号,但不能拆开各数,如把19拆成1和9是不允许的),算出2022。 能不能用代码把所有表达式逐行生成?这是我今天在群里看见吴教授出的题,他已经公布结果了,我现在要的不是结果,是用代码形式编写的方法,好复杂啊!我现在是学编程,感觉应该可以。但老鼠拉龟,无从下手,虚心请教老师。
|
-- 作者:采菊东篱下 -- 发布时间:2022/1/7 14:37:00 -- 吴教授前年也发了一个趣味题,老师帮解出来了: http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=145711&skin=0[此贴子已经被作者于2022/12/1 23:12:46编辑过]
|
-- 作者:采菊东篱下 -- 发布时间:2022/1/7 16:40:00 -- 我大约写了一下,红色报错,意思删除已用的数值,请指正。 Dim zu As Integer Dim ii As Integer Dim Names1() As Integer = {11,12,13,14,15,16,17,18,19} For i As Integer = 0 To Names1.Length -1 Dim fh1() As String = {"+","-","*","/"} For c As Integer = 0 To fh1.Length -1 zu = Names1(i) Or ("(" & Names1(i) & "\'" & fh1(c) & "\'") Names1 = Names1.RemoveAt(i) For i2 As Integer = 0 To Names1.Length -1 zu = zu & Names1(i2) Or (Names1(i2) & ")\'" & fh1(c) & "\'") Next Next If zu = 2022 Then Dim dr As DataRow = DataTables("表A").AddNew() dr = zu & Names1(i2) Or (Names1(i2) & ")\'" & fh1(c) & "\'") Next [此贴子已经被作者于2022/1/7 17:10:38编辑过]
|
-- 作者:有点蓝 -- 发布时间:2022/1/7 17:14:00 -- 数组没有RemoveAt这种用法 |
-- 作者:采菊东篱下 -- 发布时间:2022/1/7 22:25:00 -- 在字符串中统计指定字符出现个数怎统计? |
-- 作者:cjd -- 发布时间:2022/1/8 0:33:00 -- Dim s As String ="ahabcadeahgahahaiaoaaa" Dim u As Integer=0 For x As Integer=1 To 100 If s.lastindexof("a")>s.indexof("a") s=s.Substring(0,s.lastindexof("a")) u=u+1 End If If s.lastindexof("a")=s.indexof("a") Then Exit For End If Next output.show(u+1)
|
-- 作者:采菊东篱下 -- 发布时间:2022/1/8 9:09:00 -- 你这段代码我在命令窗口中执行一下,根本没反映。 |
-- 作者:采菊东篱下 -- 发布时间:2022/1/8 9:12:00 -- 有了,谢谢。 |
-- 作者:采菊东篱下 -- 发布时间:2022/1/8 11:52:00 -- 我的水平只能做到这样了,报错: .NET Framework 版本:4.0.30319.18063 Foxtable 版本:2021.12.30.1 错误所在事件:窗口,窗口1,Button1,Click 详细错误信息: Unable to cast object of type \'System.String[]\' to type \'System.Collections.Generic.IEnumerable`1[System.Int32]\'. 应该是红色标注代码问题,请教应怎么处理,另绿色标注代码能这样写吗? Dim bds As Integer Dim zu As String Dim Names() As Integer = {11,12,13,14,15,16,17,18,19} Dim s1 As New List(of Integer) Dim s2 As New List(of Integer) s1.AddRange(Names) \'将数组中的元素全部加入到集合中 s2.AddRange(s1) \'将集合s1中的元素全部加入到集合s2中 Dim fh() As String = {"+","-","*","/"} Dim t1 As New List(of Integer) Dim t2 As New List(of Integer) t1.AddRange(fh) \'将数组中的元素全部加入到集合中 t2.AddRange(t1) \'将集合s1中的元素全部加入到集合s2中 For i As Integer = 0 To s2.count -1 For c As Integer = 0 To t2.count -1 zu = s2(i) & "\'" & t2(c) & "\'" And "(" & s2(i) & "\'" & t2(c) & "\'" \'同时有两种情况,可这样写吗? Next s2.RemoveAt(i) For i2 As Integer = 0 To s2.count - 1 For c As Integer = 0 To t2.count -1 If zu Like "(*" Then zu = zu & s2(i2) & ") \'" & t2(c) & "\'" Or zu & s2(i2) & "\'" & t2(c) & "\'" Else zu = zu & s2(i2) & "\'" & t2(c) & "\'" Or zu & "\' (" & s2(i2) & "\'" & t2(c) End If Next s2.RemoveAt(i2) For i3 As Integer = 0 To s2.count - 1 For c As Integer = 0 To t2.count -1 Dim u As Integer = 0 Dim u1 As Integer = 0 For x As Integer = 1 To 100 If zu.lastindexof("(")> zu.indexof("(") zu = zu.Substring(0,zu.lastindexof("(")) u = u + 1 End If If zu.lastindexof("(") = zu.indexof("(") Then Exit For End If If zu.lastindexof(")")> zu.indexof(")") zu = zu.Substring(0,zu.lastindexof(")")) u1 = u1 + 1 End If If zu.lastindexof(")") = zu.indexof(")") Then Exit For End If Next If zu Like "(*" And (u + 1) Mod 2 = 0 And (u1 + 1) Mod 2 = 0 Then zu = zu & s2(i2) & "\'" & t2(c) & "\'" Or zu & s2(i2) & "\'" & t2(c) & "\' (" ElseIf zu Like "(*" And (u + 1) Mod 2 = 1 And (u1 + 1) Mod 2 = 0 Then zu = zu & s2(i2) & "\'" & t2(c) & "\'" Or zu & s2(i2) & "\'" & t2(c) & "\' )" End If Next s2.RemoveAt(i3) Next Next DataTables("表A").StopRedraw For Each dr As DataRow In DataTables("表A").DataRows If CDbl(zu) = 2022 Then dr = DataTables("表A").AddNew dr("表达式") = zu End If Next DataTables("表A").ResumeRedraw Next
|
-- 作者:有点蓝 -- 发布时间:2022/1/8 12:11:00 -- 自己调试生成的内容是否符合要求 For c As Integer = 0 To t2.count -1 zu = s2(i) & "\'" & t2(c) & "\'" And "(" & s2(i) & "\'" & t2(c) & "\'" \'同时有两种情况,可这样写吗? Next msgbox(zu) msgbox(CDbl(zu))
|