C语言//利用指针数组做了一个背单词小程序,有绿色红色提醒,提高了汉译的容错率,增加了英汉互听和算分的功能

容错率//满足输入子串在母串中出现且不低于母串字符数的一半

#include<stdio.h>
#include<Windows.h>
#include<string.h> 
int cmpcns(const char *p,const char *b)// 判断输入中文是否正确 (母串子串) 
{
	int k;
	if(strlen(b)<(strlen(p)/2)) return 0;//输入字符不低于母串个数一半
	for(k=0;(k<strlen(p));k++)
	{
		if(*(p+k)==*b)
		{
			b++;
		}
		if(*b=='\0') return 1;//输入字符必须在母串中出现
	}
	return 0;
}
int cmpegls(const char *p,const char *b)//判断输入英文是否正确 
{
	while(*p==*b)
	{
		if(*p=='\0') return 1;
		p++;b++;
	}
	return 0;
} 
int main()
{
	int n,i,sum=0;
	char *p[]={"awash","泛滥的","eclipse","使失色,黯然失色","routinely","惯常的,常规"};char b[20];
	n=sizeof(p)/sizeof(p[0]);//计算长度 
	system("color 7a");
	printf("请输入该单词对应的中文意思:");
	for(i=0;i<n;i=i+2)//注意是+2 
	{
		printf("\n%s\n",p[i]);
		gets(b);
		switch(cmpcns(p[i+1],b))//注意是i+1目的是比对中文 
		{
			case 1:printf("right!");system("color 2e");sleep(1);system("color 7a");sum++;break;//显示结果并变色 
			case 0:printf("wrong!正确的是:%s",p[i+1]);system("color 4e");sleep(1);system("color 7a");break;
		}
	}
	system("cls");
	printf("请输入该词对应的英文意思:");
	for(i=n-1;i>0;i=i-2)//注意是-2 
	{
		printf("\n%s\n",p[i]);
		gets(b);
		switch(cmpegls(p[i-1],b))//注意是i-1目的是比对英文 
		{
			case 1:printf("right!");system("color 2e");sleep(1);system("color 7a");sum++;break;//显示结果并变色 
			case 0:printf("wrong!正确的是:%s",p[i-1]);system("color 4e");sleep(1);system("color 7a");break;
		}
	}
	system("cls");
	printf("最终分数: %d ",sum*100/n);
	return 0;
} 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

*Min*

写的不好多多包涵~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值