第二道编程题是,判断两个字符串拼接形式是否相等 #include <iostream> using namespace std; bool func(const string &s, const string &t) { if (s.empty() && t.empty()) { return true; } if (s.size() != t.size()) { return false; } unsigned int s_count[256] = {0}; unsigned int t_count[256] = {0}; for (int i=0; i<s.size(); i++) { ++s_count[s[i]]; ++t_count[t[i]]; if (s_count[s[i]] != t_count[t[i]]) { return false; } } return true; } void main() { string s = "book"; string t = "look"; cout<<func(s , t)<<endl; system("pause"); return; }
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务