java - "codeChef INTEST" not getting 1 line in solution -



java - "codeChef INTEST" not getting 1 line in solution -

the purpose of problem verify whether method using read input info sufficiently fast handle problems branded enormous input/output warning. expected able process @ to the lowest degree 2.5mb of input info per sec @ runtime.

http://www.codechef.com/problems/intest/

input

the input begins 2 positive integers n k (n, k<=107). next n lines of input contain 1 positive integer ti, not greater 109, each. output

write single integer output, denoting how many integers ti divisible k. example

input: 7 3

1

51

966369

7

9

999996

11

output: 4

and have solution :-

import java.io.*; class main { public static void main(string[] args) throws ioexception { int ans = 0; int count = 0, n = 0, in = 0, info = 0; byte[] b = new byte[1024]; inputstream = null; seek { = new fileinputstream("g://test1.txt"); } grab (exception e) { system.out.println(e); } while ((in = is.read()) != ' ') count = count * 10 + in - '0'; // how line work ? while ((in = is.read()) != '\n') n = n * 10 + in - '0'; (int = 0; < count; i++) { in = is.read(b, 0, 1024); if (in == -1) { break; } (int j = 0; j < in; j++) { if (b[j] != '\n') { info = info * 10 + b[j] - '0'; } else { if (data % n == 0) ans++; info = 0; } } } system.out.println(ans + "ans"); } }

count = count * 10 + in - '0'; // how line work ?

count = count * 10 + in - '0'; converts character array(as sequence of input) corresponding integer value. here "in" character need subtract 0 inorder obtain actual integer value corresponding character.

example allow u wanna parse 24

you want parse character sequence integer value

you obtain 2 character '2' subtracting character '0' it

count i.e 2

when character 4 encountered obtain 4 character '4' subtracting character '0' it

now count becomes 2*10 + 4 = 24

here clean code of mine same

import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstreamreader; public class main { public static void main(string[] args) throws numberformatexception, ioexception { bufferedreader reader = new bufferedreader(new inputstreamreader( system.in)); string[] line = reader.readline().split("\\s"); int n = integer.parseint(line[0]); int k = integer.parseint(line[1]); int count = 0; (int = 0; < n; i++) { int t = integer.parseint(reader.readline()); if (t % k == 0) { ++count; } } system.out.println(count); } }

java

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -