package fr.codegym.task.task07.task0712;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
La plus petite ou la plus longue chaîne
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> list = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i=0;i<10;i++){
list.add(reader.readLine());
}
int lmax = 0;
for (int i=0;i<list.size();i++){
if (list.get(i).length() > lmax) {lmax = list.get(i).length(); }
else { }
}
int lmin = 20;
for (int i=0;i<list.size();i++){
if (list.get(i).length() < lmin) {lmin = list.get(i).length(); }
else { }
}
int lmaxf =0;
int lminf =0;
for (int i=0;i<list.size();i++){
if ((list.get(i).length() == lmin)&&(lminf!=0)){lminf = i;}
else if ((list.get(i).length() == lmax)&&(lmaxf!=0)){lmaxf = i;}
}
if (lmaxf<lminf){
System.out.println(list.get(lmaxf));
}
else {
System.out.println(list.get(lminf));
}
//écris ton code ici
}
}
My code print the good result by I don't check the mission
Discussion en cours
Commentaires (1)
- Populaires
- Nouveau
- Anciennes
Tu dois être connecté(e) pour laisser un commentaire
Gellert Varga
29 mai 2020, 22:50
I didn’t follow the logic completely, I don’t know all the trouble with the program. But some remarks:
1) "My code print the good result" but not in the following cases:
A) input list:
23
345
67898
12
4
123
1
56789876
23
1
Output:
23
But it's wrong. The correct output would be the '4'.
B) What if all of the elements of the input list is longer than 20? For example:
get(i).length() == 50 or 100 or 3456789?...
So, the "int lmin = 20;" this is not good idea.
0