View Code of Problem 3693

import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in =new Scanner(System.in);
		int n =in.nextInt();
		StringBuffer[] good = new StringBuffer[n];
		for(int i =0;i<n;i++) {
			good[i]=new StringBuffer(in.next());
		}
		StringBuffer word = new StringBuffer(in.next());
		int count=0;
		for(int i =0;i<n;i++) {
			int len = good[i].length();
			for(int j =0;j<word.length()-len+1;j++) {
				if(word.subSequence(j, j+len).toString().equals(good[i].toString())) {
					count++;
					word.delete(j, j+len);
					j--;
				}
			}
		}
		System.out.print(count);
	}
}

Double click to view unformatted code.


Back to problem 3693