Register
|
Login
Home
News
Competitions
Practice
How to
Rankings
Calendar
Arena
CodeFu 2007
CodeFu'07 Highlights
Jazoon'07 Highlights
Schedule
Rules
Prizes
Results
Competitions
»
Main CodeFu Competitons
»
CodeFu 2007
»
Results
CodeFu 2007 Results
CodeFu Final Round Results
aleksovski's solution for 300: Integer Pair, written in Java
public class IntegerPair { public int count(int N) { int c=0; for (int i=0;i<N/2;i++) if (arePair(i,N-i)) { c++; //System.out.println(i+" "+(N-i)); } return c; } private boolean arePair(int a, int b) { int min = (a<b)?a:b; int max = (a>b)?a:b; int[] cifri=getCifri(max); int bCif = getBcif(max); //int [] des={1,10,100,1000,10000,100000,1000000}; for (int i=0;i<bCif;i++) { //int m1 = max-cifri[i]*des[i]; int m1=izbrisi(i,max); if (m1==min) return true; } return false; } private int[] getCifri(int b) { int br = b; int n=0; while (br>0) { br=br/10; n++; } int [] res = new int[n]; br=b; int i=0; while (br>0) { res[i]=br % 10; i++; br=br/10; } return res; } private int getBcif(int b) { int br = b; int n=0; while (br>0) { br=br/10; n++; } return n; } private int izbrisi(int poz, int br) { String b = (new Integer(br)).toString(); String b0 = ""; String b1=""; if (poz>0) b0=b.substring(0, poz); if (poz<b.length()) b1=b.substring(poz+1); //System.out.println(b0+"_"+b1); if ((b0+b1).equalsIgnoreCase("")) return 0; else return Integer.parseInt(b0+b1); } }