用最快的方法判断所有string2的字母在string1中是否存在,如:string2="abx",string1="abcdef",ab在string1中,x不存在
提交试卷时间还没到,嘿嘿嘿嘿,不能提交,等着考完再提交吧
#include <stdio.h>
#include <stdlib.h>
#define N 256
void check(char* s, char *d, int* result){
if(s == NULL || d == NULL || result == NULL)
return;
while(*s){
result[*s]=1;
s++;
}
while(*d){
if(result[*d] == 1)
result[*d]++;
d++;
}
}
int main(void){
char s[]="abx";
char d[]="abcdef";
int result[N]={0};
int i;
check(s,d,result);
for(i = 0; i < N; i++)
if(result[i] == 1)
printf("%c: no\n", i);
else if(result[i] == 2)
printf("%c: yes\n", i);
}
#include <stdlib.h>
#define N 256
void check(char* s, char *d, int* result){
if(s == NULL || d == NULL || result == NULL)
return;
while(*s){
result[*s]=1;
s++;
}
while(*d){
if(result[*d] == 1)
result[*d]++;
d++;
}
}
int main(void){
char s[]="abx";
char d[]="abcdef";
int result[N]={0};
int i;
check(s,d,result);
for(i = 0; i < N; i++)
if(result[i] == 1)
printf("%c: no\n", i);
else if(result[i] == 2)
printf("%c: yes\n", i);
}