1791 设备编号
6.C/c++数字转字符串:
string str = to_string(i);
7.查找字符/字符串
T.find(P,begin) != strting::npos;
代码:
#include <iostream> using namespace std; class Solution { public: int GetCountNum(int start, int end) const { int count = 0; for (int i = start; i <= end; i++) { string str = to_string(i); int begin = -1; if (str.find("18", begin + 1) != string::npos || str.find("4", begin + 1) != string::npos) { count++; } } return count; } // 待实现函数,在此函数中填入答题代码; int GetNormalDeviceNum(int start, int end) const { int cnt = GetCountNum(start, end); int result = 0; result = end - start - cnt + 1; return result; } }; // 以下为考题输入输出框架,此部分代码不建议改动 inline int ReadInt() { int number; std::cin >> number; return number; } int main() { int start = ReadInt(); int end = ReadInt(); Solution solu; int result = solu.GetNormalDeviceNum(start, end); cout << result; return 0; }
以大多数人努力程度之低,根本轮不到去拼天赋~