http://ac.jobdu.com/problem.php?pid=1049
-
题目描述:
-
输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果。
-
输入:
-
测试数据有多组,每组输入字符串s和字符c。
-
输出:
-
对于每组输入,输出去除c字符后的结果。
-
样例输入:
-
heallo a
-
样例输出:
-
hello
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import
java.util.Scanner;
public
class
Main {
public
static
void
main(String[] args) {
Scanner sc =
new
Scanner(System.in);
while
(sc.hasNext()) {
String str = sc.nextLine();
String s = sc.nextLine();
char
c = s.charAt(
0
);
char
[] a = str.toCharArray();
for
(
int
i =
0
; i < str.length(); i++) {
if
(a[i] == c) {
a[i] =
'0'
;
}
}
for
(
int
i =
0
; i < a.length; i++){
if
(a[i] !=
'0'
)
System.out.print(a[i]);
}
a=
null
;
System.out.println();
}
}
}
|