标签:lse tle letters c++ isp ret push 格式 orm
string reformat(string s) {
queue<char> nums, letters;
for(char c:s) {
if(‘0‘ <= c && c <= ‘9‘) nums.push(c);
else if(‘a‘ <= c && c <= ‘z‘) letters.push(c);
}
int len1 = nums.size(), len2 = letters.size();
if(abs(len1-len2) > 1) return "";
string ans = "";
if(len1 == 0 || len2 == 0) {
if(len1 == 1 || len2 == 1) {
ans += len1 == 1 ? nums.front() : letters.front();
return ans;
}
return "";
}
if(len1 >= len2) {
while(!letters.empty()) {
ans += nums.front();
nums.pop();
ans += letters.front();
letters.pop();
}
if(len1 > len2) ans += nums.front();
}
else {
while(!nums.empty()) {
ans += letters.front();
letters.pop();
ans += nums.front();
nums.pop();
}
ans += letters.front();
}
return ans;
}
vector<vector<string>> displayTable(vector<vector<string>>& orders) {
set<string> foodList;
map<int, map<string,int> > tableList;
for(auto& o:orders) {
foodList.insert(o[2]);
tableList[stoi(o[1])][o[2]]++;
}
vector<string> title;
title.push_back("titile");
for(auto& f:foodList) {
title.push_back(f);
}
vector<vector<string> > ans;
ans.push_back(title);
for(auto& t:tableList) {
title.push_back(to_string(t.first));
for(auto& f:foodList) {
title.push_back(to_string(t.second[f]));
}
ans.push_back(title);
}
return ans;
}
标签:lse tle letters c++ isp ret push 格式 orm
原文地址:https://www.cnblogs.com/huangming-zzz/p/12730964.html