用VB编程17人围成一圈,编号为1-17从1号开始报数,报到3的倍数的人离开一直数下去,直到剩下1人,求此人编号.
Private Sub Command1_Click()
Form1.Cls
Dim a(1 To 17) As Integer
Dim i As Integer, j As Integer, k As Integer
For i = 1 To 17
a(i) = i - 1
Next
i = 0
j = 0
k = 17
Do While k > 1
For i = 1 To 17
If a(i) > -1 Then
j = j + 1
If j = 3 Then
j = 0
Print a(i)
a(i) = -1
k = k - 1
End If
End If
Next
Loop
Print "剩下的是:"
For i = 1 To 17
If a(i) > -1 Then
Print a(i)
Exit For
End If
Next
End Sub
C的
int all=17,need=17,k=3;
int x=0,y=0,i=0,j=0;
int a[5001]={0};
while(1)
{
x=x%all+1;
if(a[x]==0)
{
i=(i+1)%k;
if(i==0)
{y=y+1;a[x]=1;}
}
if(y==need)break;
}
结果是:13
CPointer.cls
---------------------------------------------------
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CPointer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
' 指针类
Private NowIndex As Integer ' 当前所指索引
Private m_Counter As Integer ' 累加计数器
Private m_RelationCollection As New Collection ' 指针关联的集合
Property Get Counter()
Counter = m_Counter
End Property
' 指向下一元素
Public Sub ToNext()
m_Counter = m_Counter + 1
If NowIndex < m_RelationCollection.Count Then
NowIndex = NowIndex + 1
Else
NowIndex = 1
End If
End Sub
' 删除当前所指元素
Public Sub Delete()
m_RelationCollection.Remove (NowIndex)
If NowIndex >= m_RelationCollection.Count Then
NowIndex = m_RelationCollection.Count
Else
NowIndex = NowIndex - 1
End If
End Sub
' 初始化指针,使其与集合关联
Public Sub Create(RelationCollection As Collection)
Set m_RelationCollection = RelationCollection
NowIndex = 1
m_Counter = 1
End Sub
' 返回当前所指值
Public Function GetValue() As Integer
GetValue = m_RelationCollection.Item(NowIndex)
End Function
form1.frm
---------------------------------------------------------
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2130
ClientLeft = 60
ClientTop = 345
ClientWidth = 3540
LinkTopic = "Form1"
ScaleHeight = 2130
ScaleWidth = 3540
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "Quit"
Height = 375
Left = 1920
TabIndex = 3
Top = 1320
Width = 975
End
Begin VB.CommandButton Command1
Caption = "Calculate"
Height = 375
Left = 720
TabIndex = 2
Top = 1320
Width = 1215
End
Begin VB.TextBox Text1
Height = 375
Left = 1200
TabIndex = 0
Top = 480
Width = 1815
End
Begin VB.Label Label1
Caption = "Result:"
Height = 375
Left = 240
TabIndex = 1
Top = 480
Width = 735
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Const HumCount = 17
Private Sub Command1_Click()
' 做初始化集合
Dim i As Integer
Dim nHuman As New Collection
For i = 1 To 17
nHuman.Add i
Next
' 初始化指针
Dim pCollection As New CPointer
pCollection.Create nHuman
' 求出结果
While nHuman.Count > 1
If pCollection.Counter Mod 3 = 0 Then
pCollection.Delete
End If
If nHuman.Count > 1 Then
pCollection.ToNext
End If
Wend
' 输入结果
Text1.Text = pCollection.GetValue
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Dim s(1 To 17) As Integer
Do Until m = 16
k = k + 1
If k > 17 Then k = 1
If s(k) = 0 Then
l = l + 1
If (l Mod 3) = 0 Then
s(k) = 1
m = m + 1
End If
End If
Loop
For i = 1 To 17
If s(i) = 0 Then Print i
Next
用VB编程,随机抽取两个人的姓名?
NameList.Add "姓名17"NameList.Add "姓名18"NameList.Add "姓名19"NameList.Add "姓名20"NameList.Add "姓名21"Dim StrGetName As String Dim a As Integer Randomize List1.Clear Do If NameList.Count > 0 Then a = Int(Rnd * NameList.Count) + 1 If StrGetName <> "" Then StrGet...
计算机二级VB考试基础知识VisualBasic的特点和版本
计算机二级《VB》考试基础知识:Visual,Basic的特点和版本很多人还不知道,现在让我们一起来看看吧! 计算机二级《VB》考试基础知识 (一)Visual Basic的特点 Visual Basic是一种可视化的、面向对象和采用事件驱动方式的结构化高级程序设计语言,可用于开发Windows环境下的各类应用程序。 总的来看,Visual Basic有以下主要特点...
vb题答案!(内部)
1.编程在窗体上输出101~500之间的所有能被3或者7整除的奇数,按照一行5个的方式输出并最后符合要求的数的和。解:代码为 Private Sub form_load()Show Dim n, sum As Integer Print Spc(6); "101~500之间的所有能被3或者7整除的奇数,及各数的和"i = 0 sum = 0 For n = 101 To 500 ...
推荐几本好的vb入门到精通的书籍 谢谢
来自vb吧的cmb666老师的推荐。。。老师很好人的,有问题可以到vb吧里讨论下下···两年多以前, 为了学习VB,我先后买了近40本VB书, 绝大部份是骗钱的垃圾,我从二楼窗户往楼下丢给那些捡破烂的至少20多本(气愤),只勉强留下14本.每个人都笑我是疯子,但没办法,我一心只想学VB, 有像我买过那么...
vb编程 有一个4×5的矩阵,各元素值由键盘输入,求所有元素的平均值,并把...
Picture1.Print "90-100分有:" & x(9) + x(10) & "人"For i = 8 To 6 Step -1 Picture1.Print i * 10 & "分—"; i * 10 + 9 & "分有" & x(i) & "人"Next i For i = 1 To 5 z = z + x(i)Next i Picture1.Print "60分以下的有:" & z & "人"...
关于VB中A*寻路算法的提问
推广:所有最短路径问题。结论:只有普遍适用的算法,没有普遍适用的代码。补充:只有问题实例化才能写出适用代码。你所遇到的可不只是寻路问题,二维寻路相对简单点,我猜测你的问题产生在“碰撞”上,建议你多学习一下“计算几何学”、“计算机图形学”、“机器人运动学”等,当然,编程的基本功也很...
运动员成绩排序,VB编程
运动员成绩排序,VB编程 10人参加运动会,运动员号和成绩如下 207号 14.5秒 077号 15.1秒 156号 14.2秒 231号 14.7秒 453号 15.2秒 276号 13.9秒 096号 15.7秒 122号 13.7秒 339号 14.9秒 302号 14.5秒 要求按成绩进行排序,并在窗体上输出名次、运动员号... 展开 ...
关于VB里统计中文及标点符号字符
include <stdio.h> include <stdlib.h> void main(){ int upper=0,lower=0,number=0,other=0,space=0;char as[200],*ps;FILE *fp;if((fp=fopen("昨天.txt","r"))==NULL){ printf("cannot open file.\\n");exit(0); } fgets(as,199,fp);fclose(fp);for( ps=as;*ps!='\\...
100分求一个用VB.net做的简单网页的代码,谢谢!!!
来源:不详 作者 佚名 点击数:31 录入时间:07-12-17 15:21:39想必大家都上过校友录吧,里面的功能虽然不是很强大,但是为我们这些毕业之后各奔西东的学子来说,到真是提供了一个好的聚集点,下面是我用vb.net做的校友录,当然也不能说是校友录了,只能说是我们班的学友录了:)不过只要你掌握了这种编程思想,...
VB 农历的计算方法
我也去答题访问个人页 关注 展开全部 你说的口算法不适合计算机语言,要在VB里处理还是建议你用楼...1994-1977=17=4×4+1 故:Q=4,R=1 则:5月7日的阴历日期为: 14×4+10.6(1+1)+(31+28+
始丽祖卡: Private Sub Form_Activate() Dim temp() As Integer, arr() As Integer, n As Integer, m As Integer, i As Integer ReDim arr(1 To 17) For i = 1 To 17 arr(i) = i Next Do Until UBound(arr) = 2 For i = 1 To UBound(arr) If i Mod 3 = 0 Then arr(i) = 0 n = n + 1 ...
通辽市18556696532: VB:求编号??
始丽祖卡: Private Sub Command1_Click() a = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17) k = -1 For i = 1 To 48 k = (k + 1) Mod 17 Do If a(k) <> "" Then Exit Do Else k = (k + 1) Mod 17 End If DoEvents Loop If i Mod 3 = 0 Then a(k) = "" Next i For j = 0 To 16 If a(j) <> "" Then MsgBox a(j) Next j End Sub
通辽市18556696532: 用VB编写程序,有17个人围成一圈(编号0~16),第0号的人开始从1报数,凡是报到3的倍数的人离开圈子,然后在数下去,直到最后只剩下一个人为止.问... - ?
始丽祖卡:[答案] C的 int all=17,need=17,k=3; int x=0,y=0,i=0,j=0; int a[5001]={0}; while(1) { x=x%all+1; if(a[x]==0) { i=(i+1)%k; if(i==0) {y=y+1;a[x]=1;} } if(y==need)break; }
通辽市18556696532: 用VB编写程序,有17个人围成一圈(编号0~16),第0号的人开始从1报数,凡是报到3的倍数的人离开 - ?
始丽祖卡: C的 int all=17,need=17,k=3; int x=0,y=0,i=0,j=0; int a[5001]={0}; while(1) { x=x%all+1; if(a[x]==0) { i=(i+1)%k; if(i==0) {y=y+1;a[x]=1;} } if(y==need)break; }
通辽市18556696532: 用VB编程17人围成一圈(编号0 - 16)第0号开始从1报数,报到3的倍数的人离开直到剩下1人,求此人编号. - ?
始丽祖卡: Dim s(1 To 17) As Integer '定义s 存放17个元素 Do Until m = 16 '做以下循环直到m=16 k = k + 1 '赋值 你懂的 If k > 17 Then k = 1 '到17为一个循环 If s(k) = 0 Then '觉得是没有给出dim k=0l = l + 1 '这个 l也没给... l是不是也等于0呢? If (l Mod 3) ...
通辽市18556696532: VB习题解答有17个人围成一圈(编号0~16),第0号的人开始从1报数,凡报道3的倍数的人离开圈子,人后再数下去.直到最后剩下一个人为止.问此人原... - ?
始丽祖卡:[答案] Private Sub Command1_Click() Cls s = "0123456789ABCDEFG" y = s: x = s Do Until Len(s) = 1 i = i + 1 If i Mod 3 = 0 ... '删除报到3的倍数的号 If i = Len(y) Then y = y & s Loop For i = 0 To Len(x) - 1 If s = Mid(x, i + 1, 1) Then Print "原位置编号是" ...
通辽市18556696532: 请教用VC做:17个人围成一个圈,依次编号为1 - 17,从第1号开始报数,报到3的倍数的人离开,直到最后1人17个人围成一个圈,依次编号为1 - 17,从第1... - ?
始丽祖卡:[答案] #include void main() { short p[17]; short i,j,n=2,countdown=17; for (i=0;i
通辽市18556696532: VB 有十七个人围成一圈(编号为0~16),第0号的人开始从1报数,凡报到3的倍数的人离开圈子,然后再数下去 - ?
始丽祖卡: Private Sub Command1_Click() Form1.Cls Dim a(1 To 17) As Integer Dim i As Integer, j As Integer, k As Integer For i = 1 To 17 a(i) = i - 1 Next i = 0 j = 0 k = 17 Do While k > 1 For i = 1 To 17 If a(i) > -1 Then j = j + 1 If j = 3 Then j = 0 Print a(i) a(i) = -1...
通辽市18556696532: 有17个人围成一圈编号1~17,从第一号开始进行1,2,3报数,凡报3者就退 - ?
始丽祖卡: #include "stdio.h" main() { int a[17]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17}; int n=17; int i,k=0; while(n>1) { for(i=0;i<17;i++) { if(a[i]==0) { continue; } k++; if(k%3==0) { a[i]=0; k=0; n--; } } } for(i=0;i<17;i++) { if(a[i]!=0) { break; } } printf("i am %d\n",a[i]); } 我写个while 你可以自己模仿写个for
通辽市18556696532: 有17个人围成一个圈,从第1号开始进行到123报数,凡报3者就退出,下个人又从1开始报数…直到最后只剩下一个人为止,请问此人原来的位置是多少号?用程序编写出来 - ?
始丽祖卡: 从编号为0的人到16,总共17人,最终留下的是10号,即第11个人留下了 static void Main(string[] args) { bool[] circles = new bool[17];//定义17个变量的数组,用来代表17个人 for (int j = 0; j < circles.Length; j++) { circles[j] = false;//为数组初始化...