最近心血来潮,毕竟在家闲得无聊,敲了一个检索的程序,不过写代码时挺快,debug倒是很费劲
程序实现的原理
查找相似度
#include<iostream>
using namespace std;
struct node{
string s;
int cnnt;
}stu[100];
/*上述结构体用于存储数据,便于与输入的进行一个比对*/
void work(){//随便命名的,可以根据自己的喜好
string tmp;
cin>>tmp;
for(int i=0;i<100;i++){
if(tmp==stu[i].s){
/* 已经检索到了*/
//在这里,执行你想要的代码
}else{
for (int j = 0; j < stu[i].s.size(); j++) {
for (int k = 0; k < tmp.size(); k += 2) {
if ((stu[i].s[j] == a[k]) && (tmp[i].s[j + 1] == a[k + 1])) {
stu[i].cnnt++;
//计数,符合当前执行条件
}
}
}
}
/*以上写的代码是关于汉字的,若是英文字符,算法类似,但是不用两个相比较了*/
}
bool flag=false;
//这里判断是否符合标准
for (int i = 0; i < 114; i++) {
if (stu[i].cnnt >= a.size() / 2 && stu[i].cnnt != 0) {
flag = true;//当前是符合标准的
}
if (flag) {
cout << "已为您找到一下题目信息\n";
//判断flag,有无题目信息,给一个
int temp = 1;
int t = 0;
for (int i = 0; i < 114; i++) {
if (stu[i].cnnt >= a.size() / 2 && stu[i].cnnt != 0) {
//输出当前查找到的资源
cout << temp << ".";
temp++;
cout << stu[i].s << endl;
}
}
} else {
cout << "当前数据暂未库,如有数据资源,请联系我们\n";/*找不到了!!!*/
}
}
希望大家能够关注我,谢谢~