美团一二题笔试分享
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]);
}
}
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++;
}
}
}
}
#美团##笔试题目#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++;
}
}
}
}