Vous êtes sur la page 1sur 2

#include<stdio.

h>
#include <string>
#define MAX 100000
/*int scanint()
{
int x;
register int c = getchar_unlocked();
x = 0;
for(;(c<48 || c>57);c = getchar_unlocked())
;
for(;c>47 && c<58;c = getchar_unlocked())
{
x = (x<<1) + (x<<3) + c - 48;
}
return x;
}*/
/*int input(char s[])
{
long int n=0;
//while((s[n++]=getchar_unlocked())!='\n')
while((s[n++]=getchar())!='\n')
s[n]='\0';
return n;
}*/
long int match(char c[], char s, char e, long int st, long int en)
{
long int i = st, j;
long int f1[MAX], f2[MAX], c1, c2, count;
c1 =c2=count=0;
while(i <= en)
{
if(c[i] == s)
f1[c1++] = i++;
else if(c[i] == e)
f2[c2++] = i++;
else
i++;
//printf("loop\n");
}
for(i=0; i<c1; i++)
for(j=0; j<c2; j++){
if(f1[i] < f2[j])
count++;
}
//printf("functin end\n");
return count;
}
int main()
{
long int i,q,start,end,n;
char c[MAX],st,en;
scanf("%s", c);
scanf("%d", &q);
getchar();
while(q--){

st=getchar();
getchar();
en=getchar();
scanf("%ld%ld", &start, &end);
getchar();
//printf("%c %c %ld %ld\n",st,en,start,end);
printf("%ld\n", match(c, st, en, start-1, end-1));
}
getchar();
getchar();
return 0;
}

Vous aimerez peut-être aussi