题目是:

一道笔试题的解法

程序为:

#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;
}



相关文章:

  • 2022-12-23
  • 2021-06-16
  • 2021-06-11
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-22
  • 2022-01-11
  • 2022-12-23
  • 2021-05-13
相关资源
相似解决方案