Files
python/LuoGu/RuMen/P1179_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

36 lines
857 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/**
* 功能:将数字转为字符串
* 作者:黄海
* 时间2019-11-23
* @param y
* @return
*/
string convertNumToStr(int y) {
string res;
stringstream ss; // 定义流ss
ss << y; // 将数字a转化成流ss
ss >> res; // 将流ss转化成字符串
return res;
}
// 一题多解知识点:数字转字符串,字符串的遍历
int main() {
ll a, b, s = 0;
cin >> a >> b;
for (ll y = a; y <= b; y++) {
string str = convertNumToStr(y);
for (auto ch : str)//ch依次取的是str里面的字符,直到取完为止
{
if (ch == '2') {
s++;
}
}
}
cout << s << endl;
return 0;
}