c語言中刪除數(shù)組中一個數(shù) c語言有n個整數(shù),去除其中重復的數(shù)字?
c語言有n個整數(shù),去除其中重復的數(shù)字?代碼示例://只需調用函數(shù)trim#include<stdio。H>無效修剪(int arr[,int*PN){int i,J,kfor(I=0I<*
c語言有n個整數(shù),去除其中重復的數(shù)字?
代碼示例:
//只需調用函數(shù)trim
#include<stdio。H>
無效修剪(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(“刪除重復元素前的數(shù)組:”)
(I=0I<n-1i)
{
printf(%d”,arr[I])
}
printf(%dn”,arr[n-1])
trim(arr,&n)
printf(“刪除重復元素后的數(shù)組:”)
(I=0I<n-1i)
{
printf“,arr[n-1])
}
printf(%dn”,arr[n-1])
返回0
}
C語言,刪除數(shù)組中的重復數(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}//刪除重復字符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)}擴展數(shù)據(jù)刪除排序數(shù)組中的重復項。注意:不要使用額外的數(shù)組空間。必須就地修改輸入數(shù)組并使用o(1)額外的空間,這意味著您無法通過創(chuàng)建新數(shù)組來解決問題。您可以考慮添加一個游標(名為:index)來遍歷整個數(shù)組。當前者和后者不相等時,光標將自動添加。這樣就可以直接跳過同一個元素而不進行統(tǒng)計,最后返回“cursor size 1”(即非重復元素的個數(shù))。