#include <iostream> | |
using namespace std; | |
int main() { | |
ios_base::sync_with_stdio(false); | |
cin.tie(NULL); | |
int n, cnt = 0; | |
cin >> n; | |
if (n < 100) cout << n; | |
else { | |
for (int i = 100, j = i; i <= n; j = ++i) { | |
int t = (i % 10) - (i / 10 % 10); | |
bool chk = true; | |
while (j / 10 > 0) { | |
int a = j % 10, b = j / 10 % 10; | |
if (a - b != t) { | |
chk = false; | |
break; | |
} | |
j /= 10; | |
} | |
if (chk) cnt++; | |
} | |
cout << cnt + 99; | |
} | |
return 0; | |
} |
using System; | |
class Program { | |
public static void Main() { | |
int n = int.Parse(Console.ReadLine()), cnt = 0; | |
if (n < 100) Console.Write(n); | |
else { | |
for (int i = 100, j = i; i <= n; j = ++i) { | |
int t = (i % 10) - (i / 10 % 10); | |
bool chk = true; | |
while (j / 10 > 0) { | |
int a = j % 10, b = j / 10 % 10; | |
if (a - b != t) { | |
chk = false; | |
break; | |
} | |
j /= 10; | |
} | |
if (chk) cnt++; | |
} | |
Console.Write(cnt + 99); | |
} | |
} | |
} |
import java.util.Scanner; | |
class Main { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
int n = sc.nextInt(), cnt = 0; | |
if (n < 100) System.out.print(n); | |
else { | |
for (int i = 100, j = i; i <= n; j = ++i) { | |
int t = (i % 10) - (i / 10 % 10); | |
boolean chk = true; | |
while (j / 10 > 0) { | |
if ((j % 10) - (j / 10 % 10) != t) { | |
chk = false; | |
break; | |
} | |
j /= 10; | |
} | |
if (chk) cnt++; | |
} | |
System.out.print(cnt + 99); | |
} | |
} | |
} |
n = int(input()) | |
if n < 100: print(n) | |
else: | |
cnt = 99 | |
for i in range(100, n + 1): | |
j = i | |
t = (i % 10) - (i // 10 % 10) | |
chk = True | |
while j // 10 > 0: | |
if ((j % 10) - (j // 10 % 10)) != t: | |
chk = False | |
break | |
j //= 10 | |
if chk: cnt += 1 | |
print(cnt) |
import java.util.Scanner | |
fun main() { | |
val sc = Scanner(System.`in`) | |
var n = sc.nextInt() | |
if (n < 100) print(n) | |
else { | |
var cnt: Int = 99 | |
for (i in 100..n) { | |
val t = (i % 10) - (i / 10 % 10) | |
var j = i; | |
var chk: Boolean = true | |
while (j / 10 > 0) { | |
if ((j % 10) - (j / 10 % 10) != t) { | |
chk = false | |
break | |
} | |
j /= 10 | |
} | |
if (chk) cnt++ | |
} | |
print(cnt) | |
} | |
} |
const fs = require('fs') | |
let n = parseInt(fs.readFileSync(0).toString()) | |
if (n < 100) console.log(n) | |
else { | |
let cnt = 99 | |
for (let i = 100, j = i; i <= n; j = ++i) { | |
let t = (i % 10) - (parseInt(i / 10) % 10), chk = true | |
while (parseInt(j / 10) > 0) { | |
if ((j % 10) - (parseInt(j / 10) % 10) != t) { | |
chk = false | |
break | |
} | |
j = parseInt(j / 10) | |
} | |
if (chk) cnt++ | |
} | |
console.log(cnt) | |
} |
import 'dart:io'; | |
void main() { | |
int n = int.parse(stdin.readLineSync()!); | |
if (n < 100) print(n); | |
else { | |
int cnt = 99; | |
for (int i = 100, j = i; i <= n; j = ++i) { | |
int t = (i % 10) - (i ~/ 10 % 10); | |
bool chk = true; | |
while (j ~/ 10 > 0) { | |
if ((j % 10) - (j ~/ 10 % 10) != t) { | |
chk = false; | |
break; | |
} | |
j ~/= 10; | |
} | |
if (chk) cnt++; | |
} | |
print(cnt); | |
} | |
} |
입력값 N이 100보다 작을 경우 두 자릿 수의 값은 모두 등차수열을 이룸으로 N을 출력하면 된다.
N이 100이상일 경우 이중반복문을 사용해 문제를 해결했는데 N의 최댓값이 1000으로 한정되있으므로
이중반복문을 사용해도 괜찮다는 판단을 했다.