c語(yǔ)言中刪除數(shù)組中一個(gè)數(shù) c語(yǔ)言有n個(gè)整數(shù),去除其中重復(fù)的數(shù)字?
c語(yǔ)言有n個(gè)整數(shù),去除其中重復(fù)的數(shù)字?代碼示例://只需調(diào)用函數(shù)trim#include<stdio。H>無(wú)效修剪(int arr[,int*PN){int i,J,kfor(I=0I<*
c語(yǔ)言有n個(gè)整數(shù),去除其中重復(fù)的數(shù)字?
代碼示例:
//只需調(diào)用函數(shù)trim
#include<stdio。H>
無(wú)效修剪(int arr[,int*PN)
{
int i,J,k
for(I=0I<*PNI)
{
for(J=I 1J<*PN)
{
if(arr[I]==arr[J])
{
]for(k=J 1K<*PNK)
arr[k-1]=arr[k
](*PN)-
}else
J
}else
J
}inter Main()
{
inti,n=20,arr[20]={12,12,2,203657001001366,12,12,50,50,50100525700700}
printf(“刪除重復(fù)元素前的數(shù)組:”)
(I=0I<n-1i)
{
printf(%d”,arr[I])
}
printf(%dn”,arr[n-1])
trim(arr,&n)
printf(“刪除重復(fù)元素后的數(shù)組:”)
(I=0I<n-1i)
{
printf“,arr[n-1])
}
printf(%dn”,arr[n-1])
返回0
}
C語(yǔ)言,刪除數(shù)組中的重復(fù)數(shù)字然后輸出?
#include<stdio。H>#包含<string。H>#define size delete uurepeat(char*str)voidbubble uSort(char*str)intmain(){charstr[size]get(str)delete repeat(str)bubble sort(str)puts(str)return0}//刪除重復(fù)字符void delete repeat(char*str){/*1]}str[strlen(str)-1]=“0”I--}//bubble sort void bubbleusort(char*str){intswapchartempintk=strlen(str)do{swap=0for(inti=0i<k-1i){if(str[i]>str[i1]){swap=1temp=str[i]str[i]=str[i1]str[i1]=temp}K--}while(K>0&;swap)}擴(kuò)展數(shù)據(jù)刪除排序數(shù)組中的重復(fù)項(xiàng)。注意:不要使用額外的數(shù)組空間。必須就地修改輸入數(shù)組并使用o(1)額外的空間,這意味著您無(wú)法通過(guò)創(chuàng)建新數(shù)組來(lái)解決問(wèn)題。您可以考慮添加一個(gè)游標(biāo)(名為:index)來(lái)遍歷整個(gè)數(shù)組。當(dāng)前者和后者不相等時(shí),光標(biāo)將自動(dòng)添加。這樣就可以直接跳過(guò)同一個(gè)元素而不進(jìn)行統(tǒng)計(jì),最后返回“cursor size 1”(即非重復(fù)元素的個(gè)數(shù))。