2017省赛A第6题

2017省赛A第6题

填空上:a[i][j] = a[i-1][j-1] + 1;

#include<iostream>
#include<cstring>
using namespace std;
const int N = 300;
char a[N], b[N];
int vis[N][N];
int maxx = 0;
void solve(const char* x, const char* y) {
	int lenx = strlen(x);
	int leny = strlen(y);
	for (int i = 0; i < lenx; i++) {
		for (int j = 0; j < leny; j++) {
			if (x[i] == y[j]) {
				vis[i+1][j+1] = vis[i][j]+1;
				if (maxx < vis[i+1][j+1])maxx =vis[i+1][j+1];
			}
		}
	}
}

int main() {
	while (cin >> a >> b) {
		memset(vis, 0, sizeof(vis));
		maxx = 0;
		solve(a, b);
		cout << maxx<<endl;
			
	}
}

仅供个人温习

上一篇:百年孤独


下一篇:Struts2 原理