gta5必须联网吗:帮忙编个程序:两个二维字符数组,各有字符串若干.要求将两者合并,合并后的字符数组中不能出现相同的字符串

来源:百度文库 编辑:中科新闻网 时间:2024/05/02 08:56:11
例如:
A数组{"assume","bunch","composer","dinner"}
B数组{"azalea","bunch","carry","composer","dinner"}
合并后的数组{"assume","azalea","bunch","carry“,"compose","dinner"}
要求:两个数组各自的串不能少于10个,相同的串不能少于3个.

#include<stdio.h>
#include<string.h>
void main()
{
int i,j,k=4;//k初始化成a的长度
int result = 0;//标志是否存在相同字符串
char a[200][10]={"assume","bunch","composer","dinner"};
char b[5][10]={"azalea","bunch","carry","composer","dinner"};

for(i=0;i<5;i++) //i是控制数组b
{
for(j=0;j<4;j++) //j控制数组a
{
if(strcmp(b[i],a[j]) == 0)
{
result = 1;//只要有一个相同标志为1
break;
}
}
if (!result)//只有都不相同的情况才保存
{
strcpy(a[k],b[i]);
k++;
}
result = 0;//标志复位
}
输出
for(j=0;j < k;j++)
{
printf("%s\n",a[j]);
}
}

public class test {

public static void main(String[] args) {
String [] tem1 = {"assume","bunch","composer","dinner","sky","jerry","ken","kiko","kuku","summer"};
String [] tem2 = {"azalea","bunch","carry","composer","dinner","ken","cate","king","sky","kuku"};
String [] result;
boolean isRep;
List temp = new ArrayList();
//取出不一样的
for(int i = 0; i < tem1.length; i++){
isRep = false;
for(int j = 0; j < tem2.length; j++){
if(tem1[i].equals(tem2[j])){
isRep = true;
break;
}
}
if(isRep == false) {
temp.add(tem1[i]);
}
}
//合并
for(int i = 0; i < tem2.length; i++) {
temp.add(tem2[i]);
}
int len = temp.size();
result = new String [len];
for(int i = 0; i < temp.size(); i++) {
result[i] = temp.get(i).toString();
System.out.println(result[i]);
}
}
}