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

相关推荐

07-25 11:12
重庆大学 C++
既然这么缺人,为什么挂我呢
飞花断音:华为需要学历不高,但是很能干事儿,能吃苦也没怨言,愿意无偿加班,最好上有老下有小,不是独生子女,家庭条件不好,家在外地租房住,生活成本高,不会轻易跳槽,并且愿意接受低工资的奴仆任劳任怨地给任总的女儿买大别墅住
点赞 评论 收藏
分享
代码飞升:别用口语,后端就写后端,前端就写前端,最后别光后悔
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务