2014年05月14日

practice 2-4:restart compile function squeeze(s1,s2),delete any match characters between string s1 and s2.
#include
#define MAXLINE 1000
void squeeze(char s1[],char s2[]);
void show(char s[]);
main()
{
 char str1[MAXLINE],str2[MAXLINE];
 gets(str1);
 gets(str2);
 squeeze(str1,str2);
 show(str1);
 return 0;
}
void squeeze(char s1[],char s2[])
{
 int i,j;

 for(i=0;s1[i]!='\0';i++)
  for(j=0;s2[j]!='\0';j++)
  {
   if(s1[i]==s2[j])
    s1[i]='0';
  }

}
void show(char s[])
{
 int i;
 for(i=0;s[i]!='\0';i++)
  if(s[i]!='0')
   putchar(s[i]);
}


practice 2-5:write a function any(s1,s2),compare string s1 and s2,find out the position of any words of string s2 come out at the first time in the string s1,and take it as a result output,if none of those was found,return -1
#include
#define MAXLINE 100
int any(char s1[],char s2[]);

main()
{
 char s1[MAXLINE],s2[MAXLINE];
 gets(s1);
 gets(s2);

 any(s1,s2);
 return 0;
}
int any(char s1[],char s2[])
{
 int i,j,flag=0;
 int num=0;


 for(i=0;s2[i]!='\0';i++)
  for(j=i+1;s2[j]!='\0';j++)
  {
   if(s2[j]==s2[i])
    s2[j]=0;
  }
 for(i=0;s2[i]!='\0';i++)
  if(s2[i]==0)
   s2[i]=s2[i+1];
 for(i=0;s2[i]!='\0';i++)
 {
  for(j=0;s1[j]!='\0';j++)
  {
   if(s1[j]==s2[i])
   {
    flag=1;
    ++num;
    break;
   }
  }
  if(flag==1)
  {
   flag=0;
   printf("%c\t%d\n",s2[i],j+1);
   
  }
 }
 
 if(num==0)
  printf("%d",-1);
 return 0;
}
practice 2-10 write a function lower(),transform capital letter into lowercase.use condition expression like ? : to compile.
#include

void lower(char c)
{
 printf("%c",(c>='a'&&c<='z')?(c+'A'-'a'):c);
 
}
main()
{
 int c;
 while((c=getchar())!=EOF)
 {
  lower(c);
 }
 return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值