Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main(){
  6. int q;
  7. cout << "Type the queries number: ";
  8. cin >> q;
  9. while(q--){
  10. string str;
  11. cout << "Type the text: ";
  12. cin >> str;
  13. int l = (int)str.length();
  14. int arr[l][l];
  15. for(int i=0;i<str.length();i++){
  16. for(int j=0;j<str.length()-i;j++){
  17. if(i==0){
  18. arr[j][j]=1;
  19. if(j!=str.length()-1)
  20. arr[j+1][j]=0;
  21. // cout << arr[j][j+i] << " ";
  22. continue;
  23. }
  24. if(str[j+i]==str[j]){
  25. arr[j][j+i]=arr[j+1][j+i-1]+2;
  26. // cout << arr[j][j+i] << " ";
  27. continue;
  28. }
  29. arr[j][j+i]=max(arr[j+1][j+i], arr[j][j+i-1]);
  30. // cout << arr[j][j+i] << " ";
  31. }
  32. // cout << endl;
  33. }
  34. cout << arr[0][l-1] << endl;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement