九度OJ---1049

来源:互联网 发布:php 支付宝api接口 编辑:程序博客网 时间:2024/04/27 20:28

http://ac.jobdu.com/problem.php?pid=1049


题目描述:

输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果。

输入:

测试数据有多组,每组输入字符串s和字符c。

输出:

对于每组输入,输出去除c字符后的结果。

样例输入:
healloa
样例输出:
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
importjava.util.Scanner;
publicclass Main {
 
    publicstatic void main(String[] args) {
        Scanner sc = newScanner(System.in);
        while(sc.hasNext()) {
            String str = sc.nextLine();
            String s = sc.nextLine();
            charc = s.charAt(0);
            char[] a = str.toCharArray();
            for(inti = 0; i < str.length(); i++) {
                if(a[i] == c) {
                    a[i] = '0';
                }
            }
            for(inti = 0; i < a.length; i++){
                if(a[i] != '0')
                    System.out.print(a[i]);
            }
            a=null;
            System.out.println();
        }
    }
}

0 0