http://euler.synap.co.kr/prob_detail.php?id=38
Skillist 설명---------------------------------------------------------------------------------
public static void main(String[] args){
int max = 0;
for(int i=1;i<10000;i++){
String now = "";
int j;
for(j=1;j<10;j++){
now += String.valueOf(i*j);
if(now.length()>=9){
break;
}
}
if(now.length()==9 && j!=1){
int total = 0;
for(int k=0;k<9;k++){
if(now.charAt(k) == '0'){
break;
}else if(now.charAt(k)=='1'){
total+=1;
}else if(now.charAt(k)=='2'){
total+=10;
}else if(now.charAt(k)=='3'){
total+=100;
}else if(now.charAt(k)=='4'){
total+=1000;
}else if(now.charAt(k)=='5'){
total+=10000;
}else if(now.charAt(k)=='6'){
total+=100000;
}else if(now.charAt(k)=='7'){
total+=1000000;
}else if(now.charAt(k)=='8'){
total+=10000000;
}else if(now.charAt(k)=='9'){
total+=100000000;
}
}
if(total == 111111111 && max<Integer.parseInt(now)){
max = Integer.parseInt(now);
}
}
}
System.out.println(max);
}
다시 공부---------------------------------------------------
public static void main(String arg[]){
int max = 0;
for(int i=1; i<10000;i++){
StringBuffer now = new StringBuffer();
int j;
for(j=1;;j++){
now.append(String.valueOf(i*j));
if(now.length() >= 9){
break;
}
}
if(now.length() == 9 && confirm(Integer.valueOf(now.toString()))){
if(max < Integer.valueOf(now.toString())){
max = Integer.valueOf(now.toString());
}
}
}
System.out.println(max);
}
public static boolean confirm(int n){
HashSet<Integer> set = new HashSet<Integer>();
int temp = n;
while(temp>0){
if(temp%10!=0 && set.add(temp%10)){
temp/=10;
}else{
return false;
}
}
if(set.size()==9){
return true;
}
return false;
}
'코딩 테스트 > Project Euler @ kr' 카테고리의 다른 글
40) 어떤 무리수에서 소수점 n번째 자리 숫자 알아내기 (0) | 2017.02.26 |
---|---|
39) 가장 많은 직각삼각형이 만들어지는 둘레(≤ 1000)의 길이는? (0) | 2017.02.26 |
36) 10진법과 2진법으로 모두 대칭수인 1,000,000 이하 숫자의 합 (0) | 2017.02.25 |
34) 각 자릿수의 팩토리얼을 더했을 때 자기 자신이 되는 수들의 합은? (0) | 2017.02.20 |
33) 이상한 방법으로 약분할 수 있는 분수 찾기 (0) | 2017.02.20 |