Advertisement
Saleh127

Light oj(LO) 1110

May 17th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. string dp[200][200];
  6.  
  7. string minn(string a,string b)
  8. {
  9. if(a.size()==b.size())
  10. {
  11. if(a<b) return a;
  12. else return b;
  13. }
  14. else if(a>b) return a;
  15. else return b;
  16. }
  17.  
  18.  
  19.  
  20. int main()
  21. {
  22. ios_base::sync_with_stdio(0);
  23. cin.tie(0);
  24. cout.tie(0);
  25.  
  26. string a,b,c;
  27. ll i,j,k,l,n,m;
  28.  
  29. test
  30. {
  31.  
  32. cin>>a>>b;
  33.  
  34. n=a.size(),m=b.size();
  35.  
  36.  
  37. a="o"+a;
  38. b="o"+b;
  39.  
  40. for(i=0; i<n+2; i++)
  41. {
  42. for(j=0; j<m+3; j++)
  43. {
  44. dp[i][j].clear();
  45. }
  46. }
  47.  
  48. for(i=1; i<=n; i++)
  49. {
  50. for(j=1; j<=m; j++)
  51. {
  52. if(a[i]==b[j])
  53. {
  54. dp[i][j]=dp[i-1][j-1]+a[i];
  55. }
  56. else
  57. {
  58. c.clear();
  59. c=minn(dp[i-1][j],dp[i][j-1]);
  60. dp[i][j]=c;
  61. }
  62. }
  63. }
  64.  
  65. cout<<"Case "<<cs<<": ";
  66.  
  67. if(dp[n][m].size()==0) cout<<":("<<endl;
  68. else cout<<dp[n][m]<<endl;
  69.  
  70. }
  71.  
  72. return 0;
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement