科大讯飞笔试第二题 - 模拟开冲
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);
}
![](https://uploadfiles.nowcoder.com/images/20220815/318889480_1660553763718/D9FDAE9918A39C99254A9D8D179628E5)
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);
}
全部评论
第三题蹲
相关推荐
![](https://static.nowcoder.com/fe/file/oss/1715049343797JOCFB.png)
点赞 评论 收藏
分享
![](https://static.nowcoder.com/fe/file/oss/1716965564844UEBJN.png)
![](https://static.nowcoder.com/fe/file/oss/1716965585666UBBME.png)
TP-LINK
| 校招
| 超多精选岗位
点赞 评论 收藏
分享
2024-12-28 15:13
桂林电子科技大学 Web前端 点赞 评论 收藏
分享
![](https://static.nowcoder.com/fe/file/oss/1716965564844UEBJN.png)
![](https://static.nowcoder.com/fe/file/oss/1716965585666UBBME.png)
腾讯
| 实习
| 超多精选岗位
点赞 评论 收藏
分享