|
|
вернуться в форумJava TLE Test #4 Послано Kunik 16 фев 2014 03:02 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StreamTokenizer; public class Solving { public StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); public PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) throws IOException { new Solving().run(); }
public int nextInt() throws IOException { in.nextToken(); return (int) in.nval; } public void run() throws IOException { int num = this.nextInt(); int[] arr = new int[num]; int a = 0; int b = 0; for (int iter1 = 0; iter1 < num; iter1++) { arr[iter1] = this.nextInt() + this.nextInt(); } StringBuilder str = new StringBuilder(); for (int iter2 = (arr.length - 1); iter2 > 0; iter2--) { a = arr[iter2]/10 + arr[iter2 - 1]%10; str.insert(0, (a%10 + b)); b = a/10; } if (b != 0) { str.insert(0, b); } str.append(arr[arr.length - 1]%10); this.out(str.toString()); } public void out(String str) { out.println(str); out.flush(); } } I don't know how make this faster. Help me please. Edited by author 16.02.2014 03:25 Re: Java TLE Test #4 Послано Noob 16 фев 2014 14:30 How do you think what is the complexity of StringBuilder.insert() method? |
|
|