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
Marina's solution for 300: Integer Pair, written in Java
import java.io.*; import java.util.*; import java.lang.*; public class IntegerPair { static boolean dif(int x, int y){ ArrayList A=new ArrayList(); ArrayList B=new ArrayList(); int max=0; int min=0; if (x>y) {max=x; min=y;} else if(x<y) {max=y; min=x;} while(max>0){ int cifmax=max%10; A.add(cifmax); max/=10; } while(min>0){ int cifmin=min%10; B.add(cifmin); min/=10; } if (A.size()==B.size()) return false; else { int l=A.size()-B.size(); for(int i=1; i<l; i++) B.add(0); } int k=0; while(B.size()>0 && k<2){ if(A.get(0)!=B.get(0)){ A.remove(0); k++; } else { A.remove(0); B.remove(0); } } if(k==1) return true; else if(A.size()==1 && B.size()==0) return true; else return false; } public int count(int n){ int k=0; int isti=0; for(int i=0; i<=n; i++){ if(dif(i, n-i)) { k++; if (i==n-i) isti=1; } } k-=isti; k/=2; return k; } }