Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. int contResp, contaux = 0;
  8.  
  9. int teste(string string1, string stringaux,int aux1, int aux2, int cont){
  10. if(string1[aux1] == stringaux[aux2] && aux1< string1.length() && aux2<stringaux.length()){
  11. cont++;
  12. contaux = aux2+1;
  13. stringaux[aux2] = '^';
  14. return teste(string1, stringaux, aux1+1, aux2+1,cont);
  15. }else if(string1[aux1] != stringaux[aux2] && aux2<stringaux.length()-1){
  16. return teste(string1, stringaux, aux1, aux2+1, cont);
  17. }else if(aux2 == stringaux.length()-1 && stringaux[aux2]!= string1[aux1]){
  18. return teste(string1, stringaux, aux1+1,contaux, cont);
  19. }
  20. if(aux1 == string1.length()-1) {
  21. return cont;
  22. }
  23.  
  24. }
  25.  
  26. int main() {
  27.  
  28. string string1, string2, stringaux;
  29.  
  30. while(getline(cin,string1)){
  31.  
  32. getline(cin,string2);
  33. stringaux = string2;
  34.  
  35. int contaux;
  36.  
  37. for (int i = 0; i<string1.length(); i++){
  38. stringaux = string2;
  39. contaux = teste(string1, stringaux, i, 0,0);
  40.  
  41. if (contaux > contResp){
  42. contResp = contaux;
  43. }
  44. }
  45.  
  46. cout << contResp << endl;
  47. }
  48.  
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement