题目是:
程序为:
#include<iostream>
#include<string>
using namespace std;
string format(string macstr)
{
string formatedstr = "";
for(int i = 0; i < macstr.size(); i++)
{
char c = macstr[i];
if((c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z')
|| (c >= '0' && c <= '9'))
{
formatedstr.append(1,c);
}
}
for(int j = 2; j < formatedstr.size(); j += 3)
{
formatedstr.insert(j,1,':');
}
return formatedstr;
};
int main()
{
string s = "00:50-8d-49-db";
cout << "formated: " << format(s) << endl;
s = "00:508d-49-db";
cout << "formated: " << format(s) << endl;
return 1;
}