gpt4 book ai didi

c - 我试图找到数组中仅使用一次的数字。

转载 作者:行者123 更新时间:2023-11-30 21:03:47 24 4
gpt4 key购买 nike

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//finds the number that is used only once
void t(int c, int a[]){
int i,j;

for(i=0;i<c;i++){
for(j=i+1;j<c;j++){
if(a[i]==a[j]){
a[i]=0;
a[j]=0;
}
}
}

for(i=0;i<c;i++){
if(a[i]!=0)
printf("%d\n",a[i]);
}

}

请找出t函数中的错误,因为编译器没有显示任何错误..

这里有什么问题吗?;

      if(a[i]==a[j]){
a[i]=0;
a[j]=0;
}

最佳答案

如果一个数字出现三次(比如说),那么当你找到第一对时,你将它们设置为零;这意味着你找不到第三次出现。如果您知道应该只有一个唯一的数字,那么您也许可以计算匹配项,然后在完成循环但没有找到匹配项时存储索引。

关于c - 我试图找到数组中仅使用一次的数字。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21056195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com