import java.util.Scanner; public class Main { public static void main(String[] args) { cha
importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[]args){charweight...
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
char weight[] = new char[10];
char values[] = new char[20];
Scanner scanner = new Scanner(System.in);
String input = scanner.next();
String valueString = scanner.next();
char temp;
if (input == null && "".equals(input)) {
System.out.println("please input somethign number .");
return;
} else {
weight = input.toCharArray();
if (weight.length > 10) {
return;
}
}
if (valueString == null && "".equals(valueString)) {
System.out.println("please input somethign number .");
return;
} else {
values = valueString.toCharArray();
if (values.length > 20) {
return;
} else {
for (int i = 0; i < values.length; i++) {
for (int j = i + 1; j < values.length; j++) {
int ai = findIndex(values[i], weight);
int aj = findIndex(values[j], weight);
if (ai > aj) {
temp = values[i];
values[i] = values[j];
values[j] = temp;
}
}
}
}
}
for (int i = 0; i < values.length; i++) {
System.out.print(values[i]);
}
}
private static int findIndex(char c, char[] weight) {
// TODO Auto-generated method stub
if (weight != null && weight.length > 0) {
for (int i = 0; i < weight.length; i++) {
if (c == weight[i]) {
return i;
}
}
}
return 0;
}
} 展开
public class Main {
public static void main(String[] args) {
char weight[] = new char[10];
char values[] = new char[20];
Scanner scanner = new Scanner(System.in);
String input = scanner.next();
String valueString = scanner.next();
char temp;
if (input == null && "".equals(input)) {
System.out.println("please input somethign number .");
return;
} else {
weight = input.toCharArray();
if (weight.length > 10) {
return;
}
}
if (valueString == null && "".equals(valueString)) {
System.out.println("please input somethign number .");
return;
} else {
values = valueString.toCharArray();
if (values.length > 20) {
return;
} else {
for (int i = 0; i < values.length; i++) {
for (int j = i + 1; j < values.length; j++) {
int ai = findIndex(values[i], weight);
int aj = findIndex(values[j], weight);
if (ai > aj) {
temp = values[i];
values[i] = values[j];
values[j] = temp;
}
}
}
}
}
for (int i = 0; i < values.length; i++) {
System.out.print(values[i]);
}
}
private static int findIndex(char c, char[] weight) {
// TODO Auto-generated method stub
if (weight != null && weight.length > 0) {
for (int i = 0; i < weight.length; i++) {
if (c == weight[i]) {
return i;
}
}
}
return 0;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询