1、输入两个字符串,从第一个字符串删除第二个字符串中所有的字符
例如:
输入:
welcome to my home
aeiou
输出:
wlcm t my hm
思路:遍历str1,将除了str2的字符放入list集合中,输出集合元素即可。
public class removeChar {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s1 = sc.nextLine();
String s2 = sc.nextLine();
ArrayList<Character> res = removeChar.remove(s1,s2);
//方法一:遍历
for (int i = 0; i < res.size(); i++) {
System.out.print(res.get(i));
}
//方法二:for each遍历
for(char c:res){
System.out.print(c);
}
}
public static ArrayList<Character> remove(String s1,String s2){
ArrayList list = new ArrayList();
for (int i = 0; i < s1.length(); i++) {
char c = s1.charAt(i);
if(!s2.contains(c+"")){
list.add(s1.charAt(i));
}
}
return list;
}
}
2、输入描述:输入第一行包括一个整数N(1<=N<=100),代表学生的个数,接下来的N行每行表示两个整数p和q,分别代表每个学生的学号和成绩。
输出描述:按照学生的成绩从小到大进行排序,并将排序后的学生信息打印出来,如果学生的成绩相同,则按学号的大小从小到大排序。
输入例子:
3
1 90
2 87
3 92
输出:
2 87
1 90
3 92