北航机试字符串匹配

版权声明:感谢阅读,欢迎批评指正。 https://blog.csdn.net/skyejy/article/details/88746046

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		String line=null;
		while((line=bf.readLine())!=null)
		{
			int n=Integer.parseInt(line);
			String str[]=new String[n];
			for(int i=0;i<n;i++)
			{
				str[i]=bf.readLine();
			}
			String pattern=bf.readLine().toLowerCase();
			for(int i=0;i<n;i++)
			{
				if(str[i].toLowerCase().matches(pattern))
				{
					System.out.println(i+1+" "+str[i]);
				}
			}
		}
	}

}

猜你喜欢

转载自blog.csdn.net/skyejy/article/details/88746046
今日推荐