Problem:
F: // The format in the bb.txt log file is:
Get or post IP or domain name traffic (separated by spaces); get the traffic in which the submission method is get, and the IP address is the traffic limit and;
For example, get 127.0.0.1 15
Get www.sina.com 20
Get 192.168.0.1 33
Post 127.0.0.1 11
Get 128.123.0.1 11
The answer is: 59.
Public class iptest {<br/> Public static void main (string [] ARGs) throws ioexception {<br/> file = new file ("F: // bb.txt "); <br/> filereader Fr = new filereader (File); <br/> bufferedreader BR = new bufferedreader (FR); <br/> string I; <br/> List <string> List = new arraylist <string> (); <br/> while (I = BR. readline ())! = NULL) {<br/> list. add (I); <br/>}< br/> int sum = 0; <br/> for (INT m = 0; m <list. size (); m ++) {<br/> string a = List. get (m); </P> <p> int Re = iptest. sub (a); <br/> sum = sum + RE; <br/>}< br/> system. out. println (SUM); </P> <p >}< br/> Public static int sub (string a) {<br/> int K =. indexof (''); <br/> string AA =. substring (0, k); <br/> string B =. substring (k + 1); <br/> Int J = B. indexof (''); <br/> string AB = B. substring (0, J); <br/> string AC = B. substring (J + 1); <br/> If (AA. equals ("get ")) {<br/> string IP = "([1-9] | [1-9] // d | 1 // d {2} | 2 [0-4]/ /d | 25 [0-5]) (//. (// d | [1-9] // d | 1 // d {2} | 2 [0-4] // d | 25 [0-5]) {3} "; <br/> pattern P = pattern. compile (IP); <br/> If (P. matcher (AB ). matches () {<br/> return integer. parseint (AC); <br/>}< br/> return 0; <br/>}< br/>}
welcome: