μ°μ κΈ°λ‘ πͺ
[λ°±μ€ 1065] νμ (C++) λ³Έλ¬Έ
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;
}
}
'Problem Solving > BOJ' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[λ°±μ€ 9461] νλλ° μμ΄ (C++) (0) | 2021.12.03 |
---|---|
[λ°±μ€ 1011] Fly me to the Alpha Centauri (C++) (0) | 2021.12.02 |
[λ°±μ€ 1541] μμ΄λ²λ¦° κ΄νΈ(C++) (0) | 2021.08.13 |
[λ°±μ€ 1676]- ν©ν λ¦¬μΌ 0μ κ°μ(C++) (0) | 2021.07.30 |
[λ°±μ€ 1463] -1λ‘λ§λ€κΈ°(C++)/λ€μ΄λλ―Ή νλ‘κ·Έλλ° (0) | 2021.07.29 |