program main implicit none character*50000::S character*10::c(5000) integer*8::snum(50000) integer*8::shash(10,50000) integer*8::chash(5000) integer::clen(5000) integer::M,i,j,slen integer*8::match=0,tmp read *,S read *,M read *,c(1:M) clen(1:M) = LEN_TRIM(c(1:M)) slen = LEN_TRIM(S) do i=1,slen snum(i) = ICHAR(S(i:i))-ICHAR('A') + 1 end do do i=1,slen tmp = 1 do j=1,10 if(i+j-1.gt.slen) exit tmp = tmp + snum(i+j-1) * 26_8**(j-1) shash(j,i) = tmp end do end do do i=1,M tmp = 1 do j=1,clen(i) tmp = tmp + (ICHAR(c(i)(j:j))-ICHAR('A') + 1) * 26_8**(j-1) end do chash(i) = tmp end do do j=1,M tmp = clen(j) ! print '(a,i0)',"chash:",chash(j) ! print *,shash(tmp,1:slen) do i=1,slen if(shash(tmp,i).eq.chash(j)) then match = match + 1 end if end do end do print '(i0)',match end program main