麻烦大佬看看那些case没有想到(华为14号机试)
第一题:只过25%
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int row = sc.nextInt();
sc.nextLine();
int col = sc.nextInt();
char[] chars = new char[col];
int count = 0;
for (int i = 0; i < row; i++) {
sc.nextLine();
for (int j = 0; j < col; j++) {
char c = sc.next().charAt(0);
if (c == 'C' && !judge(j, chars)) count++;
chars[j] = c; //更新状态
}
}
System.out.println(count);
}
//判断之前遍历相邻的是否有C
private static boolean judge(int j, char[] chars) {
return judgeCharsIsC(j, chars) ||
judgeCharsIsC(j - 1, chars) ||
judgeCharsIsC(j + 1, chars);
}
private static boolean judgeCharsIsC(int j, char[] chars) {
if (j >= 0 && j < chars.length) return chars[j] == 'C';
return false;
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
//推箱子
public class Main2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int row = sc.nextInt();
List<Integer> list = new ArrayList<Integer>();
while(sc.hasNext()) list.add(sc.nextInt());
int[] nums = new int[list.size()];
int a = 0;
for(int num : list){
nums[a] = list.get(a++);
}
int ans = nums[0];
int temp = nums[0];
for(int i = 1; i < nums.length; i++) {
if (nums[i] > temp) {
ans += nums[i] - temp;
}
temp = nums[i];
}
System.out.println(ans);
}
}
#学习路径##Java#
