Sub defen()
Dim a As String, b As String
For n = 1 To 3 '需芦贺要改下这里,这是行数
a = fenzu(Cells(n, 1))
paixu a
b = fenzu(Cells(n, 2))
paixu b
If a = b Then
Cells(n, 3) = 2
Else
If InStr(1, a, b) Then
Cells(n, 3) = 1
Else
Cells(n, 3) = 0
End If
End If
Next
End Sub
'防止答案或漏哗搜者标准答案顺序不对返历,按字母顺序排序
Sub paixu(shu As String)
Dim a, c
Dim i As Integer, temp
a = Split(shu, ",")
For i = 0 To UBound(a) - 1
If (a(i) >a(i + 1)) Then '若是递减,改为a(i)<a(i+1)
temp = a(i)
a(i) = a(i + 1)
a(i + 1) = temp
End If
Next
shu = Join(a, "")
End Sub
'为了排序,每个字母之间插入逗号
Function fenzu(t As Range) As String
Dim a As String, b As String
a = ""
b = UCase(t)
For m = 1 To Len(b)
a = a &Mid(b, m, 1) &","
Next
fenzu = Mid(a, 1, Len(a) - 1)
End Function
#include<stdio.h>#define MaxLen 4
void main()
{
int i=0//蠢雹题号
int count[MaxLen]//记录选项被选的次数
char ch//题目选项
for(int j=0j<MaxLenj++)
count[j]=0
printf("请输入您的选项<选项在ABCD中>,输入#结束输入\n")
printf("第%d题:\n",++i)
scanf("%c",&ch)
getchar()//接收键盘输入的空格
while(1)
{
if(ch=='#')//输入#直接跳出
break
printf("第%d题:\n",++i)
switch(ch)
{
case 'A':
case 'a':
count[0]++
break
case 'B':
case 'b':
count[1]++
break
case 'C':
case 'c':
count[2]++
break
case 'D':
case 'd':
count[3]++
break
default:
printf("对不起猜穗您的输入不正确,请重新输入")//输入不正确时重新输入
i--//题号还原
break
}
printf("请输入您的选项<选项在ABCD中>\n")
scanf("%c",&ch)
getchar()//接收键盘输入的空穗档卜格
}
printf("A被选%d次,B被选%d次,C被选%d次,D被选%d次\n",count[0],count[1],count[2],count[3])//输出abcd被选的次数
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)