解题思路:
注意事项:
参考代码:
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner=new Scanner(System.in);
int lenth=scanner.nextInt();
int counter=scanner.nextInt();
System.out.println();
if ((1>lenth||lenth>1000)||(1>counter||counter>1000)) {
System.out.println("输入超限");
return;
}
int[]numbers=new int[lenth];
for (int i = 0; i < lenth; i++) {
numbers[i]=scanner.nextInt();
}
for (int i = 0; i < counter; i++) {
int x=scanner.nextInt();
int y=scanner.nextInt();
System.out.println();
if (x<1||y>lenth) {
System.out.println("值超限");
return;
}
if (x==y) {
continue;
}
int num=0;
int index=0;
int num2;
for (int j = 0; j < numbers.length; j++) {
if (x==numbers[j]) {
if (num==0) {
index=j;
num=numbers[j];
}
else {
num2=numbers[j];
numbers[j]=num;
numbers[index]=num2;
}
}
else if (y==numbers[j]) {
if (num==0) {
index=j;
num=numbers[j];
}
else {
num2=numbers[j];
numbers[j]=num;
numbers[index]=num2;
}
}
}
}
for (int i = 0; i < numbers.length; i++) {
System.out.println(numbers[i]);
}
}
0.0分
1 人评分
C语言训练-角谷猜想 (C语言代码)浏览:1768 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:443 |
【数组的距离】 (C语言代码)浏览:787 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:941 |
字符串比较 (C语言代码)答案错误????浏览:641 |
A+B for Input-Output Practice (V) (C语言代码)浏览:640 |
校门外的树 (C语言代码)浏览:733 |
字符逆序 (C语言代码)浏览:645 |
企业奖金发放 (C语言代码)浏览:2462 |
C二级辅导-等差数列 (C语言代码)浏览:891 |