第一题
AC代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
String[] words = input.split(" ");
StringBuilder result = new StringBuilder();
String prevWord = "";
for (String word : words) {
if (!word.equalsIgnoreCase(prevWord)) {
result.append(word).append(" ");
prevWord = word;
}
}
String output = result.toString().trim();
System.out.println(output);
}
}
第二题