#include <string.h>
#include <stdlib.h>
#include <time.h>
#define L 100 //定义最大字符长度为 100
int main()
{
srand(unsigned(time(NULL)))
char str[L] = {}, teststr[L] = {}
int length, RightCount = 0
float Precision
length = rand() % L + 1 //生成随机的字符串长度
for (int i = 0 i < length i++)
{
str[i] = rand() % 26 + 'a' //默认字符为小写字符
putchar(str[i])
}
printf("\nPlease input the above string :\n")
gets(teststr) //保存输入的字符串
for (int i = 0 i < length i++)//计算准确的字符个数
{
if (teststr[i] == str[i]) RightCount++
}
Precision = RightCount * 1.0 / length//计算准确率
printf("Precision : %.2f%\n", Precision * 100) //准确率保留两位小数输出
return 0
}
测试样例:
jvgvmsnpfia
Please input the above string :
jlkjlsnfdas
Precision : 27.27
不知道这个合不合你意 哈哈#include<stdio.h>#include<time.h>
#include<stdlib.h>int main()
{
int i,j,count1=0,count2=0,c=1
char ch[100],data[100]
srand(time(NULL))
for(i=0i<100i++)
{
j = rand()%52 + 0
if(j<26)
{
c = 2
ch[i] = j + 'A'
}
else
ch[i] = j + 'A' + 6
}
if(c == 1)
{
printf("等级为1\n")
for(i=0i<100i++)
printf("%c",ch[i])
}
else
{
printf("等级为2\n")
for(i=0i<100i++)
printf("%c",ch[i])
}
printf("\n")
for(i =0i<100i++)
{
scanf("%c",&data[i])
}
for(i=0i<100i++)
{
if(data[i] == ch[i])
{
printf("%c",data[i])
count1++
}
else
{
printf("*")
count2++
}
}
printf("\n")
printf("对了%d个\n",count1)
printf("错了%d个\n",count2)
return 1
}数字可以自己改的!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)