Excuses, Excuses!
来源:互联网 发布:js 判断 运算符号 编辑:程序博客网 时间:2024/05/20 05:29
题目:Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid serving. In order to reduce the amount of time required listening to goofy excuses, Judge Ito has asked that you write a program that will search for a list of keywords in a list of excuses identifying lame excuses. Keywords can be matched in an excuse regardless of case.
思路:字符串的处理
import java.io.BufferedReader;import java.io.InputStreamReader;import java.util.Scanner;public class Main { public static void main(String[] args){ Scanner input=new Scanner(new BufferedReader(new InputStreamReader(System.in))); while (input.hasNext()) { String s=input.nextLine(); String[] sNum=s.split(" "); int k=Integer.parseInt(sNum[0]); int e=Integer.parseInt(sNum[1]); String[] strk=new String[k]; String[] stre=new String[e]; String[] strel=new String[e]; int[] count=new int[e]; int max=0; for (int i = 0; i < strk.length; i++) { strk[i]=input.nextLine().toLowerCase(); } for (int i = 0; i < strel.length; i++) { stre[i]=input.nextLine(); strel[i]=stre[i].toLowerCase(); String temp=""; for (int j = 0; j < strel[i].length(); j++) { if (Character.isLetter(strel[i].charAt(j))) {//判断strel[i].charAt(j)是否为字母 temp=temp+strel[i].charAt(j); }else { temp=temp+"#";//若不是字母则用#代替 } } strel[i]=temp; //借口字符串和关键词字符串进行处理 for (int j = 0; j < strk.length; j++) { //分情况讨论 当strel[i]存在关键词时,进行计数 if (strel[i].indexOf("#"+strk[j]+"#")!=-1) { count[i]++; }else if (strel[i].indexOf(strk[j]+"#")==0) { count[i]++; }else if (strel[i].indexOf("#"+strk[j])+strk[j].length()==strel[i].length()) { count[i]++; } } } //找出最大count值 for (int i = 0; i < count.length; i++) { if (count[i]>max) { max=count[i]; } } //输出 int index=1; System.out.println("Excuse Set #"+index++); for (int i = 0; i < count.length; i++) { if (count[i]==max) { System.out.println(stre[i]); } } System.out.println(); } }}
阅读全文
0 0
- Excuses, Excuses!
- Excuses, Excuses!
- Excuses, Excuses!
- Excuses, Excuses!
- Excuses, Excuses!
- Excuses, Excuses!
- fjnu 1850 Excuses, Excuses!
- UVa 409 Excuses, Excuses!
- 409-Excuses, Excuses!
- 409 - Excuses, Excuses!
- poj1598 Excuses, Excuses!
- uva 409 Excuses, Excuses!
- UVa 409 Excuses! Excuses!
- UVa 409 - Excuses, Excuses!
- uva-409 - Excuses, Excuses!
- uva409 - Excuses, Excuses!
- POJ 1598 Excuses, Excuses!
- poj 1598 Excuses, Excuses!
- Docker实战之创建一个tomcat容器
- POJ 3281 浅谈网络流基础建模
- MySQL数据库localhost的root用户登陆遭遇失败
- JSP中利用JSTL标签对日期格式化
- 自定义的一些加密条件,可叠加形成加解密方案
- Excuses, Excuses!
- Linux上传和下载之Xshell
- 利用Docker搭建java项目开发环境
- swig+crf++0.58+java环境配置详解(win+linux)
- 将博客搬至CSDN
- Java开发之富文本编辑器TinyMCE
- VMware中创建Ubuntu16.0.4虚拟桥连方式无法上网
- 自定义view-饼图
- VMware中让虚拟机支持虚拟化