#include
void main(){
char s[80]="1234";
char t[80]="24677";
char u[80];
char flag,*sp,*tp,*up;
sp=s;
tp=t;
up=u;
while(*tp++){
flag=0;
while(*sp++){
if(*sp==*tp){
flag=1;
break;
}
}
if(flag==0)
*up++=*tp;
}
printf("\nU=%s",u);
getch();
}
#include
#include
#include
int main(void)
{
char S[] = "12345";
char T[] = "24677";
char U[100];
char TmpC = 0;
int Uindex = 0;
bool IsInS = false;
memset(U,0x0,sizeof(U));
for ( int i = 0 ; i < strlen(T) ; i++ )
{
TmpC = T[i];
IsInS = false;
for ( int j = 0 ; j < strlen(S) ; j++ )
{
if ( TmpC == S[j] )
{
IsInS = true;
break;
}
}
if ( ! IsInS )
{
U[Uindex] = TmpC;
Uindex++;
}
}
printf("S=%s T=%s U=%s\n",S,T,U);
getchar();
return 0;
}
如果不要求高效率算法的话,直接暴力就可以解决问题,把S里的每个字符和T里的对照一下,有的就不用管了,没有的就放到U里去:
#include
void main()
{
char S[100], T[100], U[100];
int i, j, k, flag;
scanf("%s", S); //输入S
scanf("%s", T); //输入T
k = 0;
for (i = 0; T[i] != '\0'; i++)
{
flag = 1;
for (j = 0; S[j] != '\0'; j++)
{
if (T[i] == S[j])
{
flag = 0;
break;
}
}
if (flag)
{
U[k++] = T[i];
}
}
U[k] = 0;
printf("%s\n", U); //输出U
}
#include
#include
#define N 100
int main()
{
char s[N],t[N],u[N];
int i,j,k,lens,lent,c;
scanf("%s%s",s,t);
lens = strlen(s);
lent = strlen(t);
for(i = 0,k = 0;i < lent;i++)
{
c = 0;
for(j = 0;j < lens;j++)
{
if(t[i]==s[j])
{
break;
}
else
{
c++;
}
}
if(c==lent)
{
u[k++] = t[i];
}
}
u[k] = '\0';
puts(u);
return 0;
}