daily pastebin goal
13%
SHARE
TWEET

Pasti Pas!

a guest Jan 9th, 2014 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package others;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.InputStreamReader;
  5.  
  6. /**
  7.  * Pasti Pas! (ICPC2013 Jakarta).
  8.  *
  9.  * @author Izhari Ishak Aksa
  10.  */
  11. public class Problem6439 {
  12.  
  13.     public static void main(String[] args) throws Exception {
  14.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  15.         int TC = Integer.parseInt(br.readLine());
  16.         for (int t = 1; t <= TC; t++) {
  17.             String s = br.readLine();
  18.             int i = 0, j = s.length() - 1, ret = 0, x = 1000003;
  19.             long L = 0, R = 0, P = 1;
  20.             while (i <= j) {
  21.                 L = L * P + s.charAt(i);
  22.                 R = R + s.charAt(j) * P;
  23.                 P = P * x;
  24.                 if (L == R && i < j) {
  25.                     ret += 2;
  26.                     L = 0;
  27.                     R = 0;
  28.                     P = 1;
  29.                 }
  30.                 i++;
  31.                 j--;
  32.             }
  33.             if (P != 1) {
  34.                 ret++;
  35.             }
  36.             System.out.println("Case #" + t + ": " + ret);
  37.         }
  38.     }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top