public static void getTrueString() { Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.nextLine()); for (int i = 0; i < n; i++) { char[] str = sc.nextLine().toCharArray(); LinkedList<Character> list = new LinkedList<>(); for (char ch : str) { int index = list.size(); if ((index - 2) >= 0 && list.get(index - 1) == ch && list.get(index - 2) == ch) { //三个相同 continue; } if ((index - 3) >= 0 && list.get(index - 3) == list.get(index - 2) && list.get(index - 1) == ch) { continue; } list.add(ch); } for (int j = 0; j < list.size(); j++) { System.out.print(list.get(j)); } System.out.println(); } }
点赞 1

相关推荐

01-12 17:45
门头沟学院 Java
985废物一枚:就是问问你能不能接受北京的房租,hr也知道公司工资不高,大概率是要贴钱的
找实习记录
点赞 评论 收藏
分享
2025-12-22 15:04
江西农业大学 Web前端
SaviorSu:直接说下学期可以请假,一般情况学校允许我26届,大三就直接去实习了
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务