科大讯飞笔试第二题 - 模拟开冲
public static void main(String[] args) {
int n,k;
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
k = scanner.nextInt();
String end = scanner.nextLine();
String line = scanner.nextLine();
int[] consume = new int[n];
char[] arr = line.toCharArray();
for(int i=0;i consume[i] = arr[i] - 'a' + 1;
}
int now = 0;
int energy = k;
while(now+1 int x = consume[now+1]-consume[now];
if(x>0){
energy -= x;
}else{
energy += Math.abs(x);
}
if(energy<0){
System.out.println(-1);
return;
}
now++;
}
System.out.println(energy);
}
int n,k;
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
k = scanner.nextInt();
String end = scanner.nextLine();
String line = scanner.nextLine();
int[] consume = new int[n];
char[] arr = line.toCharArray();
for(int i=0;i
}
int now = 0;
int energy = k;
while(now+1
if(x>0){
energy -= x;
}else{
energy += Math.abs(x);
}
if(energy<0){
System.out.println(-1);
return;
}
now++;
}
System.out.println(energy);
}
全部评论
第三题蹲
相关推荐
mmvvcc:没通过你就偷着乐吧,这样的进去你天天受气
点赞 评论 收藏
分享