Problem Solving/BOJ
[λ°±μ€ 1065] νμ (C++)
kite707
2021. 12. 1. 23:07
https://www.acmicpc.net/problem/1065
1065λ²: νμ
μ΄λ€ μμ μ μ Xμ κ° μλ¦¬κ° λ±μ°¨μμ΄μ μ΄λ£¬λ€λ©΄, κ·Έ μλ₯Ό νμλΌκ³ νλ€. λ±μ°¨μμ΄μ μ°μλ λ κ°μ μμ μ°¨μ΄κ° μΌμ ν μμ΄μ λ§νλ€. Nμ΄ μ£Όμ΄μ‘μ λ, 1λ³΄λ€ ν¬κ±°λ κ°κ³ , Nλ³΄λ€ μκ±°λ
www.acmicpc.net
μμ΄λμ΄
1~99λ νμκ° 1,2,3,4 .... 99κ°μ΄λ (ν μ리, λ μ리 μλ λͺ¨λ νμμ΄λκΉ) μ λ ₯λ°μ μκ° 100μ΄μμΌ κ²½μ° 100λΆν° ν΄λΉ μ κΉμ§ νμμΈμ§ 체ν¬νλ©΄ λλ€. ν μλ¦¬μ© μλΌ λ°°μ΄μ λ£κ³ λ·μ리 μμμ μμ리 μλ₯Ό λΉΌλ©° νμμΈμ§ 체ν¬νλ€.
μ½λ
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int cnum = 0;
cin >> cnum;
if (cnum < 100) {
cout << cnum;
}
else {
int ans = 99;
bool flag = true;
for (int i = 100; i <= cnum; i++) {
vector<int> tmp;
int number = i;
string strnum = to_string(number);
for (int kk = 0; kk < strnum.size(); kk++) {
tmp.push_back(number % 10);
number /= 10;
}
for (int j = 0; j < tmp.size() - 2; j++) {
if (tmp[j] - tmp[j + 1] != tmp[j+1] - tmp[j + 2]) {
flag = false;
break;
}
}
if (flag) {
ans++;
}
flag = true;
}
cout << ans;
}
}