program main implicit none character*50000::S character*10::c(5000) integer::clen(5000) integer::M,i,j integer*8::match=0 read *,S read *,M read *,c(1:M) clen(1:M) = LEN_TRIM(c(1:M)) ! print *,S(1:LEN_TRIM(S)) ! print *,M ! print *,c(1:M) ! print *,clen(1:M) do i=1,LEN_TRIM(S) do j=1,M if(str_eq(S(i:i+clen(j)-1),c(j))) then match = match + 1 end if end do end do print '(i0)',match contains function str_eq(S1,S2) result(equal) character(*)::S1,S2 integer::len,i logical::equal do i=1,LEN_TRIM(S2) if(S1(i:i).ne.S2(i:i)) then equal = .false. return end if end do equal=.true. end function str_eq end program main