5388. 重新格式化字符串
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;
}
1 5389.点菜展示表
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;
}