(eden)Delete character

Description:

Description

In this exercise, you will get two strings A and B in each test group and the length of every string is less than 40, you need to delete all characters which are contained in string B from string A.

The character may be space or letter.

 

Input

first line is a number n(0<n<=50), which stands for the number of test data.

the next 2*n lines contain 2*n strings, and each group of test data contain two strings A and B. There may be space in both A and B.

 

Output 

string A after delete characters, and each output is split by "\n"

if string A is null after delete, you just need to print "\n"

Sample Input

3

WE are family

aeiou

qwert

asdfg

hello world

e l

 

Sample Output

WE r fmly

qwert

howrd

 

 

Hint:

the string contains space, so you may need to use fgets() to input a string.

Capital letter and small letter cannot be ignored.

代码

 1 #include<stdio.h>
 2 #include<string.h>
 3 int main() {
 4     int n, j, i;
 5     scanf("%d", &n);
 6     getchar();
 7     while (n--) {
 8         char ch[50] = "0", result[50] = "0", ch1[50] = "0";
 9         char t;
10         fgets(ch, 50, stdin);
11         int k = strlen(ch);
12         fgets(ch1, 50, stdin);
13         int k2 = strlen(ch1);
14         int tot = 0;
15         for (i = 0; i < k + 1; i++) {
16             int b = 0;
17             for (j = 0; j < k2 + 1; j++) {
18                 if (ch1[j] == ch[i]) {
19                     b = 1;
20                 }
21             }
22             if (b == 0) {
23                 result[++tot] = ch[i];
24             }
25         }
26         for (i = 1; i <= tot; i++) {
27             printf("%c", result[i]);
28         }
29         printf("\n");
30     }
31 }

标答

1.#include<stdio.h>
2.#include<string.h>
3. 
4.#define NUMBER 256
5. 
6.void Delete(char *first, char *second) {
7.        int i;
8.        int hashtable[NUMBER];
9.        for (i = 0; i < NUMBER; i++)
10.                hashtable[i]=0;
11. 
12.        char *p = second;
13.        while (*p) {
14.                hashtable[*p]=1;
15.                p++;
16.        }
17. 
18.        char *slow = first;
19.        char *fast = first;
20.        while (*fast) {
21.                if (hashtable[*fast] == 0) {
22.                        *slow=*fast;
23.                        slow++;
24.                }
25.                fast++;
26.        }
27.        *slow='\0';
28.}
29. 
30.int main() {
31.        int num;
32.        char temp[50];
33.        scanf("%d", &num);
34.        fgets(temp, 50, stdin);
35.        while (num--) {
36.                char first[50];
37.                char second[50];
38.                fgets(first, 50, stdin);
39.                fgets(second, 50, stdin);
40.                if (first == NULL) {
41.                        printf("\n");
42.                        continue;
43.                }
44.                Delete(first, second);
45.                printf("%s\n", first);
46.        }
47.        return 0;
48.}

 

转载于:https://www.cnblogs.com/iamxiaoyubei/p/5122641.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值