文章

8

粉丝

71

获赞

0

访问

12.2k

头像
1412大整数排序
我要提问
发布于2024年3月19日 09:33
阅读数 1.6k

对字符串先进行字典排序然后按照长度排序为啥不对啊,只能通过百分之六十,求大佬解答

  1. #include<iostream>
  2. #include<vector>
  3. #include<map>
  4. #include<utility>
  5. #include<algorithm>
  6. #include<stack>
  7. #include<queue>
  8. #include<string>
  9. #include<math.h>
  10. using namespace std;
  11. static bool cmp(string &s1,string &s2){
  12. return s1.size()<s2.size();
  13. }
  14. int main(){
  15. int n;
  16. cin>>n;
  17. vector<string>ans;
  18. for(int i=0;i<n;i++){
  19. string s;
  20. cin>>s;
  21. ans.push_back(s);
  22. }
  23. sort(ans.begin(),ans.end());
  24. sort(ans.begin(),ans.end(),cmp);
  25. for(int i=0;i<n;i++)cout<<ans[i]<<endl;
  26. }

 

登录查看完整内容


登录后发布评论

3 条评论
snake VIP
2024年3月19日 09:59

好像是多组数据输入

赞(0)

哈哈宝宝游泳 : 回复 snake: 改成多组输入还是不能ac,变成百分之80了

2024年3月19日 10:35

snake : 回复 哈哈宝宝游泳: 这两个sort应该合并在一起,先比较长度,长度相同再比大小

2024年3月19日 11:58