网易有道笔试题,一道笔试题的解法

题目是:
一道笔试题的解法网易有道笔试题
程序为:
#include #include 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; }

Tags:  华为笔试题 中兴笔试题 有道笔试题 普华永道笔试题 网易有道笔试题

延伸阅读

最新评论

发表评论