//第一题:镜面反转,ABA 为NO,AHA为YES,ABC为NO,只需找到反转后和原来相同的字母('A','H','I','M','O','T','U','V','W','X','Y'),并判断是不是回文
public class Main { public static void main(String[] args) { Set<Character> set=new HashSet<>(); Character[] chars={'A','H','I','M','O','T','U','V','W','X','Y'}; Arrays.stream(chars).forEach(set::add); Scanner input=new Scanner(System.in); while (input.hasNextLine()){ System.out.println(IsExcept(set,input.nextLine())); } } private static String IsExcept(Set set,String string) { int left=0; int right=string.length()-1; while (left<=right){ if (!set.contains(string.charAt(left))||!set.contains(string.charAt(right)))return "NO"; if (string.charAt(left++)!=string.charAt(right--)){ return "NO"; } } return "YES"; } }
//第二题:闯关->只需将无道具的先冲关再将有道具的按照分数从大到小排序即可
public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); long n = input.nextLong(); PriorityQueue<Long> queue = new PriorityQueue<Long>((a, b) -> b.compareTo(a)); long current=0; while (n > 0) { long[] item=new long[]{input.nextLong(), input.nextLong()}; if (item[1]==0){ current+=item[0]; }else { queue.add(item[0]); } n--; } long max = getResult(queue, current); System.out.println(max); } private static long getResult(PriorityQueue<Long> queue, long current) { if (queue.isEmpty()) { return current; } else { while (!queue.isEmpty()) { current+=Math.max(current,queue.poll()); } return current; } } }
全部评论
(0) 回帖