Guest User

Untitled

a guest
Oct 1st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. #define endl "\n"
  4. using namespace std;
  5. int32_t main(){
  6. ios_base::sync_with_stdio(false);cin.tie(0);
  7. int T,P=1;
  8. cin >> T;
  9. while(T--){
  10. int L,cont=0;
  11. cin >> L;
  12. string a,b,aux="";
  13. cin >> a >> b;
  14. for(int i=0;i<L;i++){
  15. aux.clear();
  16. aux+=a[i]; // testando cada letra Ășnica
  17. //cout << aux << " ";
  18. if(b.find(aux)!=string::npos){cont++;}
  19. for(int j=i+1;j<L;j++){
  20. aux+=a[j]; // criando cada substring possivel
  21. //cout << aux << " ";
  22. if(b.find(aux)!=string::npos){cont++;} // procurando a substring em B
  23. else{
  24. for(int k=0;k<b.size();k++){
  25. string z=b.substr(k,aux.size()); // criando todas as substrings de tamanho igual a substring atual
  26. sort(z.begin(),z.end()); // ordenando elas por ordem alfabetica e verificando se sao iguais
  27. sort(aux.begin(),aux.end());
  28. if(z==aux){cont++;break;}
  29. }
  30. }
  31. }
  32. }
  33. cout << "Case #" << P << ": " << cont << endl;
  34. P++;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment