美团一二题笔试分享

import java.util.*;
public class Main {
static class Dingdan{
public int xuhao;
public int jiage;
public int zhongliang;
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
Dingdan[] x = new Dingdan[n];
int i=0;
while(i<n){
x[i] = new Dingdan();
x[i].xuhao=i+1;
x[i].jiage=sc.nextInt();
x[i].zhongliang=sc.nextInt();
i++;
}
Arrays.sort(x,(o1,o2)->{
if(o1.jiage+o1.zhongliang*2>o2.jiage+o2.zhongliang*2)return 1;
else if(o1.jiage+o1.zhongliang*2<o2.jiage+o2.zhongliang*2)return -1;
else {
if(o1.xuhao<=o2.xuhao)return 1;
else return -1;
}
});
int[] ans = new int[m];
int index=0;
for(int j=x.length-1;j>x.length-m-1;j--){
ans[index++]=x[j].xuhao;
}
Arrays.sort(ans);
for(int k=0;k<m;k++){
System.out.println(ans[k]);
}

}
}


import java.util.*;
public class Main {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int i=0;
int flag=0;
int flag2=0;
while(i<n){
String str = sc.next();
int length=str.length();
char c = str.charAt(0);
if((c>=65&&c<=90)||(c>=97&&c<=122)){
for(int j=0;j<length;j++){
char ch = str.charAt(j);
if((ch>=65&&ch<=90)||(ch>=97&&ch<=122))continue;
else if (ch>=48&&ch<=57){
flag=1;
continue;
}
else{
flag2=1;
}
}
if(flag==1&&flag2==0) {
System.out.println("Accept");
i++;
flag=0;
}
else{
System.out.println("Wrong");
i++;
flag2=0;
flag=0;
}
}
else {
System.out.println("Wrong");
i++;
}
}

}
}


#美团##笔试题目#
全部评论

相关推荐

字节 飞书绩效团队 (n+2) * 15 + 1k * 12 + 1w
点赞 评论 收藏
分享
贺兰星辰:不要漏个人信息,除了简历模板不太好以外你这个个人简介是不是太夸大了...
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务