题解 | #ZOJ#用map记录一下就行
ZOJ
https://www.nowcoder.com/practice/7557d470617c464f9200d93acf721471
import java.util.Map; import java.util.Scanner; import java.util.HashMap; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); Map<Character, Integer> map = new HashMap<>(); for (char c : s.toCharArray()) { map.put(c, map.getOrDefault(c, 0) + 1); } boolean flag = true; while (true) { if (map.get('Z') > 0) { System.out.print('Z'); map.put('Z', map.get('Z') - 1); flag = false; } if (map.get('O') > 0) { System.out.print('O'); map.put('O', map.get('O') - 1); flag = false; } if (map.get('J') > 0) { System.out.print('J'); map.put('J', map.get('J') - 1); flag = false; } if (flag) break; else flag = true; } } }