曲阜做网站哪家好,网站规划与建设的流程与方法 高中信息技术,黄山网站建设哪家强,建设网站考证二进制王国
题目链接
https://www.lanqiao.cn/problems/17035/learning/?contest_id177
题目描述 思路
这里就要灵活理解字典序排列#xff0c;虽然string内置可以直接比较字符串字典序#xff0c;但是在拼接时比较特殊#xff0c;比如 11的字典序小于110#xff0c;但…二进制王国
题目链接
https://www.lanqiao.cn/problems/17035/learning/?contest_id177
题目描述 思路
这里就要灵活理解字典序排列虽然string内置可以直接比较字符串字典序但是在拼接时比较特殊比如 11的字典序小于110但是11110排列大于11011不可以偏概全故我们可以想到换种比较方式用拼接的结果来比较 按照正常sort的逻辑加以修改比较s1 s2 所得的字典序和 s2 s1所得的字典序重构sort函数具体如下 #include iostream
#include algorithm
using namespace std;
const int N 2e5 10;
bool cmp(string s1, string s2) { //重构比较函数return s1 s2 s2 s1;
}
int main() {int n;cin n;vectorstring s(n 1); //这里防止题目所给数据空间开爆用变长数组for(int i 0; i n; i) cin s[i];sort(s.begin(), s.end(), cmp);for(auto str : s)cout str;return 0;
}