From 5d1aa225f17f64c35271472c16d63569a48f5ed4 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 21 Nov 2021 16:20:46 +0800 Subject: [PATCH] =?UTF-8?q?P1179=20[NOIP2010=20=E6=99=AE=E5=8F=8A=E7=BB=84?= =?UTF-8?q?]=20=E6=95=B0=E5=AD=97=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R63283669 --- Luogu/P1179/P1179.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Luogu/P1179/P1179.cpp diff --git a/Luogu/P1179/P1179.cpp b/Luogu/P1179/P1179.cpp new file mode 100644 index 00000000..50e7724a --- /dev/null +++ b/Luogu/P1179/P1179.cpp @@ -0,0 +1,23 @@ +#include + +using namespace std; + +int l, r, ans; + +int cnt2(int x) { + int res = 0; + while (x) { + res += x % 10 == 2; + x /= 10; + } + return res; +} + +int main() { + cin >> l >> r; + for (int i = l; i <= r; i++) { + ans += cnt2(i); + } + cout << ans << endl; + return 0; +}