9.7贝壳笔试 后端开发
100 100 0 0,后两道题感觉能做出来,但是第二题debug半天没时间做后面的了,终究还是太菜了
有无3,4题AC代码让我学习下
第一题写了80行。。。
附上代码 AC
public class T01 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = Integer.parseInt(sc.nextLine());
for (int i = 0; i < T; i++) {
String s = sc.nextLine();
String[] temp = s.trim().split(" ");
double left = resJ(temp,0)+resB(temp,0)+resS(temp,0);
double right = resJ(temp,1)+resB(temp,1)+resS(temp,1);
if(left == right)
System.out.println("same");
else if(left > right)
System.out.println("left");
else
System.out.println("right");
}
}
public static double resJ(String[] temp,int n){
if(temp[n].equals("J")){
if(temp[2].equals("B")){
if(temp[3].equals("B")){
return 1.0;
}else {
return 0.5;
}
}else {
if(temp[3].equals("B")){
return 0.5;
}else {
return 0;
}
}
}
return 0;
}
public static double resS(String[] temp,int n){
if(temp[n].equals("S")){
if(temp[2].equals("J")){
if(temp[3].equals("J")){
return 1.0;
}else {
return 0.5;
}
}else {
if(temp[3].equals("J")){
return 0.5;
}else {
return 0;
}
}
}
return 0;
}
public static double resB(String[] temp,int n){
if(temp[n].equals("B")){
if(temp[2].equals("S")){
if(temp[3].equals("S")){
return 1.0;
}else {
return 0.5;
}
}else {
if(temp[3].equals("S")){
return 0.5;
}else {
return 0;
}
}
}
return 0;
}
} 第二题 代码 AC
public class T02 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
String s = sc.nextLine();
if(n == 1) System.out.println(1);
else {
String ans = resCount(s,n);
int count = n - ans.length();
System.out.println(count);
}
}
public static String resCount(String s,int n){
String res = "";
for (int i = 0; i <= n/2; i++) {
String temp = s.substring(0,i);
int j = i+1;
if(j+i<=n){
String temp2 = s.substring(j,j+i);
if(temp.equals(temp2)){
res = temp;
}else continue;
}else break;
}
return res;
}
}
查看12道真题和解析