Header

  1. View current page

    정상혁의 수첩

Profile_img_60x60_08
192

Code Challenge 문제풀이 (정상혁)

 

,2번은 정상혁&이용우, 3,4,5번은 정상혁&이상미의 짝 프로그램입니다.

 

허진영 선임님 코드처럼 친절하게 최종답을 안 찍어주는 코드도 있지만 돌려보면 답이 눈에는 보이게 되어있습니다 ^^;


          import java.math.BigInteger;
          
          public class Ex1 {    
          
          private static final int N= 234;    
          
          public static void main(String[] args) {        
          
          BigInteger result = null;                
          
          for (int i=1;i<=N;i++){            
          
          if (i==1) result = new BigInteger("1");            
          
          else result = result.multiply(new BigInteger(String.valueOf(i)));        }       
          
           System.out.println(result);        
          
          System.out.println(result.toString().substring(9,20));    }}
          

          public class Ex2 {    
          
          public static void main(String args[]){        
          
          System.out.println(check(13));        
          
          System.out.println(check(123));            }        
          
          static int check(int goal){        
          
          int count = 0;        
          
          for(int i=1; i<=goal; i++){            
          
          String temp = i+"";            
          
          for(int j=0; j<temp.length(); j++){                
          
          if(temp.substring(j,j+1).equals("1")) {                    
          
          count++;                }            }        }        return count;    }}
          

          public class Ex3 {        
          
          static int N = 5882;    public static void main(String argsp[]){        for (int i=1;i<=N;i++){            int number1 = getSum(i);            int number2 = getSum(number1);            if (i==number2) {                System.out.println("진약수:" + number1 + "," + number2+ ":" + (number1 + number2));            }        }    }        static int getSum(int n){        int sum = 0;        for (int i=1;i<n;i++) if (n%i ==0) sum+=i;        return sum;    }}
          

          public class Ex4 {    public static void main(String[] args) {        for( int i=1;i<=500;i++){            if (i==getAmstrong(i))                System.out.println(i);        }    }    static int getAmstrong(int n){        int sum = 0;        String temp = n+"";        for(int j=0; j<temp.length(); j++){          int d = Integer.parseInt(temp.substring(j,j+1));              sum+=(d*d*d);        }                    return sum;    }}
          

          import java.math.BigInteger;public class Ex5 {    
          
          public static void main(String[] args) {        
          
          BigInteger  n = new BigInteger("115733321631");       
          
           int count = 0;        
          
          while(!isPalindrome(n)){            
          
          n=n.add(getRevered(n));            count++;        }        System.out.println(n);        System.out.println(count);            }        static boolean isPalindrome(BigInteger n){        String number = n.toString();        int length = number.length();        for (int i=0;i<length;i++)             if (number.charAt(i)!= number.charAt(length-1-i)) return false;        return true;    }        static BigInteger getRevered(BigInteger n){        String number = String.valueOf(n);        StringBuffer result = new StringBuffer();        int length = number.length();        for (int i=0;i<length;i++) result.append(number.charAt(length-1-i));        return new BigInteger(result.toString());    }}
          

본문크게보기
 

History

Last edited on 01/02/2010 18:15 by benelog

Comments (0)

You must log in to leave a comment. Please sign in.