合并两个字符集合为一个新集合,每个字符串在新集合中仅出现一次,函数返回新集合中字符串。

/*****************************************************
copyright (C), 2014-2015, Lighting Studio. Co.,     Ltd. 
File name:
Author:Jerey_Jobs    Version:0.1    Date: 
Description:
Funcion List: 
*****************************************************/
//合并两个字符集合为一个新集合,每个字符串在新集合中仅出现一次,函数返回新集合中字符串。
//    如:
//          s1集合{
//          “while”,”for”,”switch”,”if”,”continue”}
//                s2集合{
//                “for”,”case”,”do”,”else”,”char”,”switch”}
//                      运行结果:
//                            while   for   switch   if  break   continue   case  do  else  char
//
//                }
//          }
#include<stdio.h>
#include<string.h>


void str_cat(char a[][10], char b[][10], char c[][10], int n, int m)
{
int i;
int j;
int k=n;
int count;//比较b中字符串和a中字符串相同的个数计数


for (i = 0; i < n; i++)//字符数组a中无相同项直接拷贝到c
{
strcpy(c[i],a[i]);
}
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
if ((strcmp(b[i],a[j])) == 0)
{
count++;
      }
}
if (count == 0)//无相同项,将字符串拷贝到c
{
strcpy(c[k],b[i]);
k++;
}
count = 0;//重新赋值用于计数
}
printf("Puts string c!\n");
for (i = 0; i < k;  i++)
{
printf("%s ",c[i]);
}
printf("\n");
}


int main()
{
int i;
int j;
int numa;
int numb;
char a[10][10];
char b[10][10];
char c[20][10];


printf("Enter number of a!(<=10))!\n");//输入字符数组a的长度
scanf("%d",&numa);
printf("Enter string a!\n");


for (i = 0; i < numa; i++)//输入字符数组a
{
scanf("%s",a[i]);
}


printf("Enter number of b!(<=10))!\n");//输入字符数组b的长度
scanf("%d",&numb);
printf("Enter string b!\n");


for( j = 0; j < numb; j++)//输入字符数组b
{
scanf("%s",b[j]);
}


str_cat(a,b,c,numa,numb);


    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值