#include <iostream> using namespace std; int main(){ string s1,s2; int n,m,q; scanf("%d %d %d",&n,&m,&q); cin>>s1; cin>>s2; for(int test =0; test<q;test++){ int a,b,c,d; scanf("%d %d %d %d", &a, &b, &c, &d); a--;b--;c--;d--; // int current2=c; int counter=0; int index2=c; for(int i = a; i<=b;i++){ bool flag=true; for(;index2<=d && flag;index2++){ if(s1[i]==s2[index2]){ flag=false;counter++; } } // if(current2<=d){ // // while(s2[current2]!=s1[i] && current2<=d)current2++; // if(s1[i]==s2[current2])counter++; // current2++;} // /*while(current2<=d && s1[i]!=s2[current2]) // if(s1[i]!=s2[current2])current2++; // if(s1[i]==s2[current2])counter++;**/ } printf("%d\n",counter); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <iostream> using namespace std; int main(){ string s1,s2; int n,m,q; scanf("%d %d %d",&n,&m,&q); cin>>s1; cin>>s2; for(int test =0; test<q;test++){ int a,b,c,d; scanf("%d %d %d %d", &a, &b, &c, &d); a--;b--;c--;d--; // int current2=c; int counter=0; int index2=c; for(int i = a; i<=b;i++){ bool flag=true; for(;index2<=d && flag;index2++){ if(s1[i]==s2[index2]){ flag=false;counter++; } } // if(current2<=d){ // // while(s2[current2]!=s1[i] && current2<=d)current2++; // if(s1[i]==s2[current2])counter++; // current2++;} // /*while(current2<=d && s1[i]!=s2[current2]) // if(s1[i]!=s2[current2])current2++; // if(s1[i]==s2[current2])counter++;**/ } printf("%d\n",counter); } } |