资源限制
时间限制:1.0s 内存限制:512.0MB
问题描述
给定某整数数组和某一整数b。要求删除数组中可以被b整除的所有元素,同时将该数组各元素按从小到大排序。如果数组元素数值在A到Z的ASCII之间,替换为对应字母。元素个数不超过100,b在1至100之间。
输入格式
第一行为数组元素个数和整数b 第二行为数组各个元素
输出格式
按照要求输出
样例输入
7 2
77 11 66 22 44 33 55
样例输出
11 33 55 M
编译语言: | C++CJavaPython |
---|---|
import java.util.*;
public class 数组查找及替换 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
if (x%m!=0) {
list.add(x);
}
}
Collections.sort(list);
for (int i = 0; i < list.size(); i++) {
int x = list.get(i);
if (x>=65&&x<=90) {
System.out.print((char)x+" ");
}else {
System.out.print(x+" ");
}
}
}
}