donaricano-btn

OneNumber(한수)


1. Question    

- There is a integer X

- X has digit that is made of arithmetical sequence like 123, 468, 369

- You enter a number N( 1 <= N <=1000)

- To get a count of X within 1 <= N 

2. Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.Scanner;
 
public class ArithmeticalSequence {
     
    void count(int a){
         
        int count = 0;
         
        if(a <= 1000){
             
            for(int i = 1; i<=a; i++){
                 
                int thousandsDigit = i/1000;
                int hundredDigit = i/100%10;
                int tenDigit = i/10%10;
                int unitDigit = i%10;
                int temp0 = thousandsDigit - hundredDigit;
                int temp = hundredDigit - tenDigit;
                int temp1 = tenDigit - unitDigit;
                 
                if(thousandsDigit != 0){
                    if(temp0 == temp && temp==temp1){
                        count = count + 1;
                    }
                }else{
                    if(hundredDigit != 0){
                        if(99<i){
                            if( temp == temp1){
                                count = count + 1;
                            }
                             
                        }
                    }else{
                        count = count + 1;
                    }
                }
            }
             
        }
        System.out.println(count);
    }
     
    public static void main(String[]args){
        ArithmeticalSequence cc = new ArithmeticalSequence();
         
        Scanner aa = new Scanner(System.in);
        int b = aa.nextInt();
        cc.count(b);
        aa.close();
         
    }
}

블로그 이미지

리딩리드

,
donaricano-btn

SelfNumber


1. Question

- If you start with 33, the next number is 33 + 3 +3 = 39, the next is 39 + 3 + 9 = 51 and so you generate the sequence

33, 39, 51, 57....

- d(n) n is called a generator of d(n)

- Some numbers have more than one generator

- A number with no generators is a self-number

- Write a program to output all positive self-numbers less than 10000 in increasing order, one per line


2. Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package stepByStep;
public class SelfNum {
 
       int calc (int number) {
 
          int sum = 0;
 
          if (number < 10000){
 
             int a = number / 1000;
             int b = number / 100 % 10;
             int c = number / 10 % 10;
             int d = number % 10;
 
             sum    =    a + b + c + d + number;
 
          }
          return sum;
       }
 
       public static void main (String[] args) {
 
          SelfNum    aa       =    new SelfNum();
          int       arr[]    =   new int[10000];
          int       number    =    1;
 
          for(int i = 0; i < 10000; i++, number++) {
 
             if (aa.calc(number) < 10000) {
                arr[aa.calc(number)] = aa.calc(number);
             }
          }
 
          for (int k = 1; k < arr.length; k++) {
             if(arr[k] == 0) {
                System.out.println(k);
             }
          }
       }
    }

블로그 이미지

리딩리드

,
donaricano-btn

SmallerThanX


1. Question

1) There is two numbers N and X in the first low

2) In the second low, You should enter A progression, Size of A progression will be N

3) To print out numbers that is smaller than X  


2. Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package stepByStep;
 
import java.util.Scanner;
 
public class SmallerThanX {
     
    public static void main(String[]args){
         
        Scanner ab = new Scanner(System.in);
         
        int A = ab.nextInt();
        int X = ab.nextInt();
         
        int size[] = new int[A];
         
        for(int i = 0; i<A ; i++){
             
            int a = ab.nextInt();
            size[i] = a;
        }
         
        for(int k = 0; k< size.length; k++){
            if(X> size[k]){
                System.out.print(size[k]+" ");
            }
        }
         
    }
}

https://github.com/KyleJeong/Algorithm
블로그 이미지

리딩리드

,
donaricano-btn

SecondLargest


1. Question

There are three integers, which integer is largest thing?


2. Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package stepByStep;
 
import java.util.Scanner;
 
public class SecondLargest {
     
    public static void main(String[]args){
        Scanner br = new Scanner(System.in);
         
        int f = br.nextInt();
        int s = br.nextInt();
        int t = br.nextInt();
         
        int scale[] = {f,s,t};
        int temp;
         
        if(scale[0] < scale[1]){
            temp = scale[0];
            scale[0] = scale[1];
            scale[1] = temp;
        }
        if(scale[1] < scale[2]){
            temp = scale[1];
            scale[1] = scale[2];
            scale[2] = temp;
        }
        if(scale[0] < scale[1]){
            temp = scale[0];
            scale[0] = scale[1];
            scale[1] = temp;
        }
         
        System.out.println(scale[1]);
         
         
    }
}

https://github.com/KyleJeong/Algorithm
블로그 이미지

리딩리드

,