Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- #define endl "\n"
- using namespace std;
- int32_t main(){
- ios_base::sync_with_stdio(false);cin.tie(0);
- int T,P=1;
- cin >> T;
- while(T--){
- int L,cont=0;
- cin >> L;
- string a,b,aux="";
- cin >> a >> b;
- for(int i=0;i<L;i++){
- aux.clear();
- aux+=a[i]; // testando cada letra Ășnica
- //cout << aux << " ";
- if(b.find(aux)!=string::npos){cont++;}
- for(int j=i+1;j<L;j++){
- aux+=a[j]; // criando cada substring possivel
- //cout << aux << " ";
- if(b.find(aux)!=string::npos){cont++;} // procurando a substring em B
- else{
- for(int k=0;k<b.size();k++){
- string z=b.substr(k,aux.size()); // criando todas as substrings de tamanho igual a substring atual
- sort(z.begin(),z.end()); // ordenando elas por ordem alfabetica e verificando se sao iguais
- sort(aux.begin(),aux.end());
- if(z==aux){cont++;break;}
- }
- }
- }
- }
- cout << "Case #" << P << ": " << cont << endl;
- P++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment