华为2019.9.18笔试第一题:
判断数据是否合理,给了三种合理的情况,一个是两位数与一位数交替出现,一个是两头是两位数,中间全是一位数,最后一种情况是两头是一位数,中间全是两位数。
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main9 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
List<String> list = new ArrayList<String>();
String s;
while(true){
if((s = scanner.nextLine()).equals("")){
break;
}
list.add(s);
}
for(int i = 0; i < list.size(); i++){
String string = list.get(i);
String temp[] = string.split(" ");
int res[] = new int[temp.length];
for(int j = 0; j < temp.length; j++){
res[j] = Integer.parseInt(temp[j]);
}
System.out.print(isequ(res) + " ");
}
}
public static boolean isequ(int a[]) {
if(a[0] >= 10 && a[a.length - 1] >= 10){
for(int i = 1; i < a.length - 1; i++){
if(a[i] >= 10){
return false;
}
}
}else if (a[0] < 10 && a[a.length - 1] < 10) {
for(int i = 1; i < a.length - 1; i++){
if(a[i] < 10){
return false;
}
}
}else {
for(int i = 0; i < a.length; i++){
if(i % 2 == 0 && a[i] >= 10){
return false;
}else if(i % 2 == 1 && a[i] < 10){
return false;
}
}
}
return true;
}
}