文章

8

粉丝

37

获赞

0

访问

1.1k

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

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

#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<math.h>
using namespace std;
static bool cmp(string &s1,string &s2){
	
  return s1.size()<s2.size();
	
}
int main(){
  int n;
  cin>>n;
  vector<string>ans;
  for(int i=0;i<n;i++){
  	string s;
  	cin>>s;
  	ans.push_back(s);
  }
  
  sort(ans.begin(),ans.end());
  sort(ans.begin(),ans.end(),cmp);
  for(int i=0;i<n;i++)cout<<ans[i]<<endl;
}

 

登录查看完整内容


登录后发布评论

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

好像是多组数据输入

赞(0)

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

2024年3月19日 10:35

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

2024年3月19日 11:58