Добрый день!
Задача прошла проверку, но код не выводит правильно строки.
Прошу проверить Вашу систему проверки. Скриншот с условиями которые вводил прилагаю.
Строки ввода ( 3 строки должно вывести, а выводит одну) :
дедушка
бабушка
дочь
програм
машина
package com.javarush.task.task07.task0708;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Самая длинная строка
*/
public class Solution {
private static List<String> strings = new ArrayList<>();
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 5; i++) {
strings.add(reader.readLine());
}
ArrayList<String> list = new ArrayList<>();
list.add(strings.get(0));
int size = strings.size();
for (int i = 0; i < size; i++) {
if (i + 1 != size) {
if (list.size() == 1) {
if (strings.get(i).length() < strings.get(i + 1).length()) {
if (list.get(0).length() < strings.get(i + 1).length()) {
list.set(0, strings.get(i + 1));
} else {
if (list.get(0).length() == strings.get(i + 1).length()) {
list.add(strings.get(i + 1));
}
}
} else {
if (strings.get(i).length() == strings.get(i + 1).length()) {
if (list.get(0).length() < strings.get(i + 1).length()) {
list.set(0, strings.get(i + 1));
} else {
if (list.get(0).length() == strings.get(i + 1).length()) {
list.add(strings.get(i + 1));
}
}
} else {
if (list.get(0).length() < strings.get(i).length()) {
list.set(0, strings.get(i));
}
}
}
} else {
if (strings.get(i).length() < strings.get(i + 1).length()) {
list.clear();
list.add( strings.get(i + 1));
} else {
if (strings.get(i).length() == strings.get(i + 1).length()) {
if (list.get(list.size() - 1).length() < strings.get(i + 1).length()) {
list.clear();
list.add( strings.get(i + 1));
} else {
if (list.get(list.size() - 1).length() == strings.get(i + 1).length()) {
list.add(strings.get(i + 1));
}
}
}
}
}
}
}
for (int j = 0; j < list.size(); j++) {
System.out.println(list.get(j));
}
}
}
http://prntscr.com/m1g34t