π [λ°±μ€μκ³ λ¦¬μ¦ νμ΄] Q.1065 νμ λ¬Έμ νμ΄
π λ¬Έμ
https://www.acmicpc.net/problem/1065
μ΄λ€ μμ μ μ Xμ κ° μλ¦¬κ° λ±μ°¨μμ΄μ μ΄λ£¬λ€λ©΄, κ·Έ μλ₯Ό νμλΌκ³ νλ€.
λ±μ°¨μμ΄μ μ°μλ λ κ°μ μμ μ°¨μ΄κ° μΌμ ν μμ΄μ λ§νλ€. Nμ΄ μ£Όμ΄μ‘μ λ,
1λ³΄λ€ ν¬κ±°λ κ°κ³ , Nλ³΄λ€ μκ±°λ κ°μ νμμ κ°μλ₯Ό μΆλ ₯νλ νλ‘κ·Έλ¨μ μμ±νμμ€.
π μ κ·Όλ²
νμ λ¬Έμ μ
λλ€.
ν μλ¦Ώμ Ex {1 , 2 , 3 . . .}
λ μλ¦Ώμ EX {12, 13, 14 . . .}
λ μ΄λ―Έ μ°¨μ΄κ° μΌμ ν λ±μ°¨μμ΄μ μ΄λ£Ήλλ€.
κ·Έλ¬λ―λ‘ λ μλ¦Ώμ μ΄νλ
μμ°μ€λ½κ² νμμ ν΄λΉλ©λλ€.
μΈ μλ¦ΏμλΆν° κ° μλ¦¬κ° λ±μ°¨μμ΄μ μ΄λ£¨λμ§ νμΈνλ©΄ λ©λλ€.
π» μ½λ
package problem.brute;
import java.io.*;
public class Main_1065 {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String n = br.readLine();
int count = 0;
if(Integer.parseInt(n) < 100){
count+=Integer.parseInt(n);
}
else{
count = 99;
}
for (int i=100; i<=Integer.parseInt(n); i++) {
if (solve(Integer.toString(i)))
count++;
}
bw.write(Integer.toString(count));
bw.flush();
bw.close();
br.close();
}
public static boolean solve (String n){
String temp[] = n.split("");
int diff = 0;
if(n.length() >= 2)
diff = Integer.parseInt(temp[1]) - Integer.parseInt(temp[0]);
for(int i=2; i<temp.length; i++){
if( Integer.parseInt(temp[i]) - Integer.parseInt(temp[i-1]) != diff)
return false;
}
return true;
}
}
Written on September 23, 2020