找出长度最长的单词(不同长度的单词只出现一次)。
输入格式:
输入格式为单行形式,单词之间使用空格分割。
输出格式:
输出格式为长度最长的一个单词。
输入样例:
在这里给出一组输入。例如:
an not need happy suggest
输出样例:
在这里给出相应的输出。例如:
suggest
代码长度限制16 KB
时间限制400 ms
内存限制64 MB
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
ArrayList<String> list = new ArrayList<>();
int max = 0, num = 0;
String str = sc.nextLine();
for(String s : str.split(" ")){
list.add(s);
if(s.length() > max){
max = s.length();
num = list.indexOf(s);
}
}
System.out.println(list.get(num));
}
}
