题解 | 神秘石像的镜像序列
神秘石像的镜像序列
https://www.nowcoder.com/practice/fa34eea974234610b6d3d81790cb2949
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] arr = new int[1024];
int count = 0;
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int i=0;
while(true){
int n = in.nextInt();//1
if(n==0){
break;
}
arr[i]=n;//[1,]
count++;
i++;
}
}
int left = 0;
int right = count - 1;
while (left < right) {
// 交换
int temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
left++;
right--;
}
for(int i=0;i<count;i++){
System.out.print(arr[i]+" ");
}
}
}
查看6道真题和解析