We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
my code work perfectly if k below 6...
if the k is 7 and above, my C# code will not showing any result...i think is the max size of the data type problem...
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;classSolution{staticvoidMain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */int[]m_t=Array.ConvertAll(System.Console.ReadLine().Split(' '),arTemp=>Convert.ToInt32(arTemp));intnumDigitRepeated=m_t[0];// numDigitRepeated--;intnumInput=m_t[1];// System.Console.WriteLine(numDigitRepeated+" "+numInput);intnumDigit=-1;for(inti=0;i<numInput;i++){numDigit=Convert.ToInt32(Console.ReadLine());// System.Console.WriteLine(numDigit);//numDigit++;intfinalNumOfDigit=getCountNumOfDigit(numDigit);inttemp=getCountNumOfDigit(numDigit-1);finalNumOfDigit=finalNumOfDigit-temp;//eg if 3 digit, range(100-999) = range(1-999) - range(1-10)//System.Console.WriteLine("finalNumOfDigit:"+finalNumOfDigit);if(numDigit>numDigitRepeated){//3 > 1updateRepeatedCountNumOfDigit(reffinalNumOfDigit,numDigitRepeated,numDigit);}System.Console.WriteLine("finalNumOfDigit:"+finalNumOfDigit);}}publicstaticintgetCountNumOfDigit(intn){StringinitDigit="";for(intw=0;w<n;w++)initDigit+="0";initDigit="1"+initDigit;intfinalNumOfDigit=Int32.Parse(initDigit)-1;returnfinalNumOfDigit;}publicstaticvoidupdateRepeatedCountNumOfDigit(refintfinalNumOfDigit,intdigitRepeat,inttotalNumDigit){digitRepeat++;// System.Console.WriteLine("digitRepeat:"+digitRepeat+",totalNumDigit:"+totalNumDigit+",aaaaaaaaa");intallNumOfDigit=getCountNumOfDigit(totalNumDigit);StringinitDigit="";for(intw=1;w<digitRepeat;w++)initDigit+="0";initDigit="1"+initDigit;intstartDigit=Int32.Parse(initDigit);//System.Console.WriteLine("startDigit:"+startDigit+",allNumOfDigit:"+allNumOfDigit);for(intq=startDigit;q<=allNumOfDigit;q++){//if( Math.Floor(Math.Log10(q) + 1) >= digitRepeat ){if(checkRepeatedNumber(q,digitRepeat)){finalNumOfDigit--;}//}}}publicstaticboolcheckRepeatedNumber(intq,intdigitRepeat){Stringsss=q.ToString();// if(q==1000 ||q==2000|| q==3000 || q==4000|| q==5000|| q==6000|| q==7000|| q==8000 || q==9000)// System.Console.WriteLine("sss:"+sss);boolisRepeated=false;//int[] arr1 = Enumerable.Range(1, 9).ToArray();char[]qqq={'1','2','3','4','5','6','7','8','9'};foreach(charqqinqqq){intcountR=countFrom(sss,qq,0);//Convert.ToChar(1)//if(q==1111 ||q==2000|| q==2111) System.Console.WriteLine("countR:"+countR+",digitRepeat:"+digitRepeat);if(countR>=digitRepeat){//System.Console.WriteLine("adddddddddd"+sss);isRepeated=true;}}returnisRepeated;}publicstaticintcountFrom(Stringstr,charch,intstart){intcount=0;for(inti=start;i<str.Length;i++){inttt=str.IndexOf(ch,i,1);if(tt!=-1){count++;}}returncount;}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #172: Investigating numbers with few repeated digits
You are viewing a single comment's thread. Return to all comments →
my code work perfectly if k below 6... if the k is 7 and above, my C# code will not showing any result...i think is the max size of the data type problem...