AtCoder题解|ABC 111B
题目信息 📚
【题目描述】
Kurohashi has never participated in AtCoder Beginner Contest (ABC).
The next ABC to be held is ABC $N$ (the $N$-th ABC ever held). Kurohashi wants to make his debut in some ABC $x$ such that all the digits of $x$ in base ten are the same.
What is the earliest ABC where Kurohashi can make his debut?
【输入】
The input is given from Standard Input in the following format:
$N$
【输出】
If the earliest ABC where Kurohashi can make his debut is ABC $n$, print $n$.
【数据范围】
- $100 \leq N \leq 999$
- $N$ is an integer.
【输入样例1】
111
【输出样例1】
111
The next ABC to be held is ABC $111$, where Kurohashi can make his debut.
【输入样例2】
112
【输出样例2】
222
The next ABC to be held is ABC $112$, which means Kurohashi can no longer participate in ABC $111$. Among the ABCs where Kurohashi can make his debut, the earliest one is ABC $222$.
【输入样例3】
750
【输出样例3】
777
【题目来源】
https://atcoder.jp/contests/abc124/tasks/abc124_c
题目解析 🍉
【题目分析】
整数版的向上取整。
(a + (b - 1)) / b * b
实现的效果和 (int)(ceil(1.0 * a / b) * b)
是一样的
【C++代码】
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
int n;
cin >> n;
cout << (int) (ceil(1.0 * n / 111) * 111) << endl;
// cout << (n + 110) / 111 * 111 << endl;
return 0;
}