发布网友 发布时间:2022-04-26 22:54
共2个回答
热心网友 时间:2022-06-19 12:39
#include "stdio.h"
int Judge(const char *a,const char *b){
int s,n;
for(s=n=0;n<10;s+=a[n]==b[n++]);
return s;
}
int main(int argc,char *argv[]){
const char std[]="ABCDBBCBBC";
char ans[10],i,t;
printf("Please enter your answer(orderly sequence of ABCD)...\n");
while(1){
if(scanf("%10s",ans)==1)
for(i=0;i<10;i++)
if(ans[i]!='A' && ans[i]!='B' && ans[i]!='C' && ans[i]!='D')
break;
if(i>=10)
break;
printf("Input error, redo:\nPlease enter your answer(orderly sequence of ABCD)...\n");
}
printf("\nCorrect answer:\n");
for(t=Judge(std,ans),i=0;i<10;i++)
if(std[i]==ans[i])
printf("%2d",i+1);
printf("\nTOTAL: %d\n",10*t);
return 0;
}
代码格式和运行样例图片:
热心网友 时间:2022-06-19 12:40
public int Judge(char *input)
{
int i, sum;
char ans[11] = "ABCDBBCBBC";
for (i = 0, sum = 0, i < 10 && input[i] != '\0', i++)
{
if (input[i] == ans[i])
sum++;
}
return sum;
}