I just started Topcoder
it is very interesting for me
because i have to think about a lot of things.
this homepage is really good
I hope my coding pattern and style will be better than now~!
do you want to do this with me?
write message to me~!
this article is about tho question "practiceRooms/Inv 2001 R1/ 500"
my answer is below~!
import java.util.ArrayList;
public class SquareDigits {
public static void main(String args[]){
int a= new SquareDigits().smallestResult(112);
System.out.println(a);
}
public int smallestResult(int value){
int count =0;
ArrayList<Integer> tArray= new ArrayList<Integer>();
int sum = 0;
String sValue ="";
sValue =String.valueOf(count);
while(true){
for(int i=0; i<sValue.length(); i++){
String eachValue = sValue.substring(i, i+1);
sum = sum + Integer.parseInt(eachValue)*Integer.parseInt(eachValue);
}
if(sum == value){
if(tArray.size()==0) return count;
return tArray.get(0);
}else{
if(tArray.contains(sum)){
count=count+1;
tArray.clear();
sValue =String.valueOf(count);
sum=0;
}else{
tArray.add(sum);
sValue =String.valueOf(sum);
sum=0;
}
}
}
}
}
and my Rank is below
No comments:
Post a Comment