标签:for stack ++ can efi nbsp color top div
#include<stdio.h> #include<string.h> #include<stack> #include<algorithm> using namespace std; #define N 1010 int dp[N][N]; char c; int main() { char a[N]; char b[N]; scanf("%s%s",a,b); int la=strlen(a); int lb=strlen(b); memset(dp,0,sizeof(dp)); for(int i=1; i<=la; i++) { for(int j=1; j<=lb; j++) { if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1; else dp[i][j]=max(dp[i-1][j],dp[i][j-1]); } } int i=la,j=lb; stack<char>s; while(dp[i][j]) { if(dp[i][j]==dp[i-1][j]) { i--; } else if(dp[i][j]==dp[i][j-1]) { j--; } else if(dp[i][j]>dp[i-1][j-1]) { i--; j--; s.push(a[i]); } } while(!s.empty()) { c=s.top(); printf("%c",c); s.pop(); } return 0; }
标签:for stack ++ can efi nbsp color top div
原文地址:https://www.cnblogs.com/programyang/p/11215467.html