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(); } } |
'Algorithm&DataStructures > StepByStep' 카테고리의 다른 글
[Algorithm] 백준알고리즘_SelfNumber (0) | 2016.09.09 |
---|---|
[Algorithm] 백준알고리즘_SmallerThanX (0) | 2016.08.31 |
[Algorithm] 백준알고리즘_SecondLargest (0) | 2016.08.25 |
[Algorithm] 백준알고리즘_TestScore (0) | 2016.08.25 |
[Algorithm] 백준알고리즘_Sum (0) | 2016.08.24 |