Virus attack sustained _ hdu_3065 (string timeout). java

Source: Internet
Author: User

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission (s): 5087 Accepted Submission (s ): 1820 Problem Description small t thank you very much for helping solve his previous Problem. However, virus attacks continue. With the unremitting efforts of Mr. t, he discovered the "source of evil" in the Internet ". This is a huge virus website. It has many viruses, but the website contains very strange viruses. These viruses have very short signatures and only contain "uppercase letters ". Of course, little t really wants to harm the people, but little t never fights an unprepared war. Know yourself and know what you are doing. The first thing small t wants to do is to know the characteristics of this virus Website: How many different viruses are contained, and how many times each virus appears. Can you help him? The first line of Input, an integer N (1 <= N <= 1000), indicates the number of virus signatures. In the next N rows, each line represents a virus pattern. The character string must be 1-50 characters long and only contain "uppercase letters ". No two virus signatures are identical. In the next line, it indicates the source code of the website "the source code of all evil". The source code string length is within 2000000. The characters in the string are both visible ASCII characters (excluding carriage return ). Output is one per line in the following format, and the number of times each virus appears. No output is required for a virus that does not appear. Virus pattern: there is a space after the occurrence of the colon, Which is output in the input order of the virus pattern. Sample Input3AABBCCooxxCC % dAAAoen... END Sample OutputAA: 2CC: 1 Hint Hit: all the situations not mentioned in the title description should be considered. For example, two virus signatures may contain one another or overlap one another. The counting policy can also be inferred to some extent from the Sample. Source2009 Multi-University Training Contest 16-Host by NIT Recommendlcy | We have carefully selected several similar problems for you: 2222 2896 2243 2825 3247 [java] import java. io. bufferedReader; import java. io. inputStreamReader; import java. util. hashMap; import java. util. map; public class Main {// timeout static int a []; public static void main (String [] args) {BufferedReader bf = new BufferedReader (New InputStreamReader (System. in); try {while (true) {String g = bf. readLine (); if (g = null) break; Integer n = Integer. parseInt (g); Map <String, Integer> map = new HashMap <String, Integer> (); String s [] = new String [n]; for (int I = 0; I <n; I ++) {s [I] = bf. readLine ();} String ss = bf. readLine (); for (int I = 0; I <n; I ++) {int sum = 0; int j = 0; while (true) {int d = ss. indexOf (s [I], j + 1); if (d! =-1) {j = d; sum ++;} else break;} if (sum> 0) map. put (s [I], sum) ;}for (int I = 0; I <n; I ++) {if (map. containsKey (s [I]) System. out. println (s [I] + ":" + map. get (s [I]) ;}} catch (Exception e) {e. printStackTrace () ;}} [java] import java. io. bufferedReader; import java. io. inputStreamReader; import java. util. hashMap; import java. util. map; public class Main {// timeout static int a []; public static void main (Strin G [] args) {BufferedReader bf = new BufferedReader (new InputStreamReader (System. in); try {while (true) {String g = bf. readLine (); if (g = null) break; Integer n = Integer. parseInt (g); Map <String, Integer> map = new HashMap <String, Integer> (); String s [] = new String [n]; for (int I = 0; I <n; I ++) {s [I] = bf. readLine ();} String ss = bf. readLine (); StringBuffer s1 = new StringBuffer (ss); for (int I = 0; I <s1.length (); I ++) {I F (s1.charAt (I) >= 'A' & s1.charAt (I) <= 'Z') {s1.deleteCharAt (I) ;}} ss = s1.toString (); for (int I = 0; I <n; I ++) {int sum = 0; int j = 0; while (true) {int d = ss. indexOf (s [I], j + 1); if (d! =-1) {j = d; sum ++;} else break;} if (sum> 0) map. put (s [I], sum) ;}for (int I = 0; I <n; I ++) {if (map. containsKey (s [I]) System. out. println (s [I] + ":" + map. get (s [I]) ;}} catch (Exception e) {e. printStackTrace ();}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.