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
#include <stdio.h>
#include <string.h>
char input1[50];
char input2[50];
int main() {
int n;
scanf("%d", &n);
getchar();
while (n--) {
memset(input1, 0, sizeof(input1));
memset(input2, 0, sizeof(input2));
fgets(input1, 50, stdin);
fgets(input2, 50, stdin);
long length1 = strlen(input1);
long length2 = strlen(input2);
for (int i = 0; i < length1; i++) {
for (int j = 0; j < length2; j++) {
if (input1[i] == input2[j]) {
input1[i] = '!';
}
}
}
for (int i = 0; i < length1; i++) {
if (input1[i] != '!') {
printf("%c", input1[i]);
}
}
printf("\n");
}
return 0;
}
过不了测试,但输出正确。
#include <stdio.h>
#include <string.h>
char input1[50];
char input2[50];
int main() {
int n;
scanf("%d", &n);
while (n--) {
char temp;
scanf(" %c", &temp);
int length1 = 0;
while (temp != '\n') {
input1[length1++] = temp;
scanf("%c", &temp);
}
scanf(" %c", &temp);
int length2 = 0;
while (temp != '\n') {
input2[length2++] = temp;
scanf("%c", &temp);
}
for (int i = 0; i < length1; i++) {
for (int j = 0; j < length2; j++) {
if (input1[i] == input2[j]) {
input1[i] = '!';
}
}
}
for (int i = 0; i < length1; i++) {
if (input1[i] != '!') {
printf("%c", input1[i]);
}
}
printf("\n");
}
return 0;
}
关于fgets的思考参考:
http://www.360doc.com/content/13/1221/11/15164765_338873030.shtml