#include #include #include #include #include using namespace std; class DigitStringDiv2 { public: int count(string S, long long X); }; int DigitStringDiv2::count(string S, long long X) { int start, size; int total; string sub; long long val; istringstream ss; total = 0; /* Enumerate all starting positions and sizes. */ for (start = 0; start < S.size(); start++) { if (S[start] != '0') { for (size = 1; start+size <= S.size(); size++) { /* Extract the substring and turn it into a number. */ sub = S.substr(start, size); ss.clear(); ss.str(sub); ss >> val; /* Add one to the total if the number is big enough. */ if (val > X) total++; } } } /* Return the total. */ return total; }