description
已知a,b,c為三個元素值遞增有序的線性表,要求對錶a如下運算:刪去那些既在表b中出現又在表c中出現的元素。線性表以順序結構,編寫實現上述運算和演算法。
input
第一行輸入三個正整數m,n,用空格隔開,分別表示三個線性表的元素個數,其後三行依次輸入abc表中的元素。
output
輸出實現上述操作後的a表。
sample input
8 5 6
1 2 3 4 5 6 6 7
2 3 5 9 12
2 4 5 6 12 13
sample output
1 3 4 6 6 7
#include#includetypedef int elemtype;
typedef int status;
# define list_init_size 100
# define ok 1
# define overflow -1
typedef struct sqlist;
//初始化線性表
status initlist_sq(sqlist *l)
void create_sq(sqlist *l,int n)
void disp_sq(sqlist l)
//須保留的元素移動到新的位置
while(ilength&&la->elem[i]==same)i++;//跳過相同的元素}}
while(ilength)
la->length=m;/*先從b和c中找出共有元素,記為same,再在a中從當前位置開始,凡小於same的元素均保留(存到新的位置),
等於same的就跳過,到大於same時就再找下乙個same*/
}int main()
python列表的交 並 差集
list 的 sort 方法返回的是對已經存在的列表進行操作,而內建函式 sorted 方法返回的是乙個新的 list,而不是在原來的基礎上進行的操作 a.sort reverse true b sorted a,reverse false usr bin env python3 l1 1 2 3 ...
Go 時間交並集小工具
示例 含測試 在這裡 在甘特圖的場景下,我們經常會遇到這種情況,五位員工a,b,c,d,e,可能他們的工作都是並行的,我們需要計算 某段時間內他們總的工作時長。我們不能簡單得把五個人的工作時間都加起來,因為當中會有重疊的部分。所以這時候我們就需要乙個計算時間交並集的工具。將一組離散的時間段按照開始時...
hdu 1588 線段相交 並查集
判斷第k 個線段的集合中一共有幾條線段。先用並查集將相交的線段合併記錄,最後查詢sum陣列即可。include include includeusing namespace std struct node s 2004 struct edge e 2005 int fa 2005 int sum 2...