Loading

【烂活】checker

以前看 @LHQing 写了个可视化代码比较感觉很有意思。笔者也随便写了一个匹配(

/*
    Author : SharpnessV
    Right Output ! & Accepted !
*/
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (a);i <= (b);i++)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define si(x) (int)(x).size()

using namespace std;
#define N 2005
char s[N], pro[22];
vector<char>u[N]; 
typedef pair<double, int> pbr;
vector<pbr >ans;
int f[N][N];
double calc(int x,int y){
	int p = u[x].size(), q = u[y].size();
	if(p > N - 5 || q > N - 5)return -1;
	printf("ss %d %d\n", x, y);
	rep(i, 0, p)rep(j, 0, q)f[i][j] = 0;
	rep(i, 1, p)rep(j, 1, q){
		f[i][j] = max(f[i - 1][j], f[i][j - 1]);
		if(u[x][i - 1] == u[y][j - 1])f[i][j] = max(f[i][j], f[i - 1][j - 1] + 1);
	}
	return 1.00 * f[p][q] / max(p, q);
}
int main() {
	//int T = read();while(T--)solve();
	scanf("%s", pro);
	int T; scanf("%d", &T);
	int m = 129;
	rep(n, 1, m){
		if(n < 10)sprintf(s, "C:\\Users\\Desktop\\answers-NOIP2021\\JX-000%d\\%s\\%s.cpp", n, pro, pro);
		else if(n < 100)sprintf(s, "C:\\Users\\Desktop\\answers-NOIP2021\\JX-00%d\\%s\\%s.cpp", n, pro, pro);
		else sprintf(s, "C:\\Users\\Desktop\\answers-NOIP2021\\JX-0%d\\%s\\%s.cpp", n, pro, pro);
		freopen(s, "r", stdin);
		char ch = getchar(), pre = 0;
		int op = 0;
		//cout << "ww " << ch << endl;
		while(ch != EOF){
			if(op == 2 && ch == '/' && pre == '*')op = 0;
			if(op == 1 && ch == '\n')op = 0;
			if(op){ch = getchar(); continue;}
			if((ch == '/' && pre == '/') || ch == '#')op = 1;
			if(ch == '*' && pre == '/')op = 2;
			if(ch == '[' || ch == ']' || ch == '(' || ch == ')' || ch == '{' || ch == '}' 
				|| ch == '<' || ch == '>' || ch == '=' || ch == '+' || ch == '-' || ch == '%' || ch == '&' || ch == '|'
				|| ch == ':' || ch == ',' || ch == ';' || ch == '"' || ch == '?')
				u[n].pb(ch);
			pre = ch, ch = getchar();
		}
	}
	rep(i, 1, m)if(si(u[i]) > 100)rep(j, i + 1, m)if(si(u[j]) > 100)ans.pb(mp(calc(i, j), (i << 15) | j));
	sort(ans.begin(), ans.end(), [](pbr x, pbr y){return x > y;});
	rep(i, 0, T - 1){
		int x = ans[i].se >> 15, y = ans[i].se & 32767;
		printf("rank %d :  JX-00%d and JX-00%d   Similarity : %.6lf   Length : %d ans %d\n",
			 i + 1, x, y, ans[i].fi, si(u[x]), si(u[y]));
	}
	return 0;
}

非常简陋的代码,输入题目名称 \(pro\) 和相似度前 \(T\) 位。

原理很简单,保留关键符号,然后求最长公共子序列,效率非常低(

效果貌似还不错?

posted @ 2021-11-21 16:07  7KByte  阅读(102)  评论(0编辑  收藏  举报