class Printer
{
public:
static std::string printerError(const std::string &s);
};
std::string Printer::printerError(const std::string& s) {
vector<string> my_vec;
int l = s.size();
for (int i = 0; i < l; i++) {
my_vec.push_back(s.substr(i, 1));
}
int count = 0;
int error = 0;
string low = "a";
string high = "m";
int w;
vector<string>::iterator ib = my_vec.begin(), ie = my_vec.end();
for (; ib < ie; ib++) {
//cout << *ib << " ";
if (*ib > high || *ib < low)
count += 1;
}
return to_string(count) + '/' + to_string(l);
}
?优秀解法
class Printer
{
public:
static std::string printerError(const std::string &s)
{
return std::to_string(count_if(s.begin(), s.end(), [](char c){ return c>'m';})) + "/" + std::to_string(s.size());
}
};
|