自己的方法:
#include <stdio.h>
#include <stdlib.h>
int compare(char ch1,char y[])
{
int i=0;
for(i=0;y[i]!='\0';i++)
{
if(ch1==y[i])
return 0;
}
return 1;
}
int main()
{
int i,j=0;
char x[80],y[26]={0};
i=0;
while((x[i]=getchar())!='\n')
i++;
x[i]='\0';
for(i=0;x[i]!='\0';i++)
{
if(x[i]>='A'&&x[i]<='Z')
{
if(compare(x[i],y))
{
y[j]=x[i];
j++;
}
}
}
y[j]='\0';
for(i=0;y[i]!='\0';i++)
putchar(y[i]);
return 0;
}
书上的方法:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,j,ny=0;
char x[80],y[26];
i=0;
while((x[i]=getchar())!='\n')
i++;
x[i]='\0';
for(i=0;x[i]!='\0';i++)
{
if(x[i]>='A'&&x[i]<='Z')
{
for(j=0;j<ny;j++)
{
if(x[i]==y[j])
break;
}
if(j==ny)
{
y[ny]=x[i];
ny++;
}
}
}
y[ny]='\0';
for(i=0;y[i]!='\0';i++)
putchar(y[i]);
return 0;
}