Register
|
Login
Home
News
Competitions
Practice
How to
Rankings
Calendar
Arena
CodeFu 2010
CodeFu'10 Highlights
Jazoon'10 Highlights
Schedule
Rules
Prizes
Results
Competitions
»
Main CodeFu Competitons
»
CodeFu 2010
»
Results
CodeFu 2010 Results
Final Round Results
domenica's solution for 300: NumberSequence, written in Java, submitted on 09.05.2010 14:00:46
public class NumberSequence { public int findDigit(int N) { int dokojbroj=0; int i=9; int j=-1; int pom=N; int cif=0; int pomosna=0; int preth=0; boolean first=true; boolean aa=true; boolean aaa=true; while(pom-cif>0) { if (dokojbroj<100) { if (i-- > 0) { pomosna = cif; j++; cif += (j + 1); dokojbroj++; } else { //if(j==8) {j=9;} pomosna = cif; if (first) { j++; first = false; } else j += 2; cif += (j + 2); dokojbroj++; } } else { if(dokojbroj<1000) { pomosna = cif; if(aa){j+=2; aa=false;} else j += 3; cif += (j + 3); dokojbroj++; } else { pomosna = cif; if(aaa){j+=3; aaa=false;} else j += 4; cif += (j + 4); dokojbroj++; } } } pom=pom-pomosna; String hh=""; for(int k=1;k<=pom;k++) hh+=k; //System.out.println(hh.charAt(pom-1)); String br=""; br+=hh.charAt(pom-1); return Integer.parseInt(br); } /** * @param args */ public static void main(String[] args) { NumberSequence ns= new NumberSequence(); System.out.println(ns.findDigit(10001)); //System.out.println(ns.findDigit(1000000)); //System.out.println(ns.findDigit(1000000000)); //System.out.println(ns.findDigit(1)); // TODO Auto-generated method stub } }