Given-Strings S1 and S2, s = S1-s 2 is defined to being theremaining string after taking all the Charac Ters in S2 from S1. Your task is simply to calculate S1-s2 for any given strings. However, it might is not is, simple-to-do it fast.
Input Specification:
Each input file contains the one test case. Each case consists of lines which gives S1and S 2, respectively. The string lengths of both strings is no more than4. It is guaranteed and a new line character signals the end of the characters is visible ASCII codes and white space of a string.
Output Specification:
For each test case, the print S1-s2 in one line.
Strlen () is a loop in itself, so don't use it in the loop, it's timed out
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 10001int Main () { char str1[n] , Str2[n]; BOOL flag[92]; memset (flag,0,sizeof (flag)); Gets (STR1); Gets (STR2); int i,length; Length=strlen (STR2); for (i=0;i<length;i++) { flag[str2[i]-']=true; } Length=strlen (STR1); for (i=0;i<length;i++) { if (flag[str1[i]-']!=true) printf ("%c", Str1[i]); } printf ("\ n"); System ("pause"); return 0; }
1050. String Subtraction