Guest User

Untitled

a guest
Apr 26th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. int lcs(string a, string b,string sub){
  7. int aLen = a.length();
  8. int bLen = b.length();
  9. if (aLen==0 || bLen==0){
  10. return 0;
  11. }
  12. if(a.at(aLen-1)==b.at(bLen-1)){
  13. return 1+lcs(a.substr(0,aLen-1),b.substr(0,bLen-1),a.at(aLen-1)+sub); // add letter to subsequence
  14. }
  15. else {
  16. return max(lcs(a.substr(0,aLen-1),b.substr(0,bLen),sub),lcs(a.substr(0,aLen),b.substr(0,bLen-1),sub));
  17. }
  18. }
  19.  
  20. int main(int argc, const char * argv[])
  21. {
  22. char sub[]="";
  23. int charsInLCS = lcs("sdmc","msdc",sub); //i want to output "sdc"
  24. cout << charsInLCS << endl;
  25. return 0;
  26. }
Add Comment
Please, Sign In to add comment