题解 | #Coincidence#
Coincidence
https://www.nowcoder.com/practice/f38fc44b43cf44eaa1de407430b85e69
#include <iostream> using namespace std; int dp[105][105]; char c1[105]; char c2[105]; int main() { int a, b; while (scanf("%s%s", c1, c2) != EOF) { // 注意 while 处理多个 case string str1 = c1; string str2 = c2; for(int i = 0; i <= str1.size(); i++){ for(int j = 0; j <= str2.size(); j++){ if(0 == i || 0 == j){ dp[i][j] = 0; continue; } //走到这里的时候其实 i>=1, j>=1了,但是字符串是从0开始的,所以要减1 if(str1[i - 1] == str2[j - 1]){ dp[i][j] = dp[i - 1][j - 1] + 1; }else{ //其实这一句并不太懂是什么意思 dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); } } } printf("%d\n", dp[str1.size()][str2.size()]); } } // 64 位输出请用 printf("%lld")