gpt4 book ai didi

C++ For Loop 在进程中间被跳过。如何解决?

转载 作者:搜寻专家 更新时间:2023-10-31 02:02:16 24 4
gpt4 key购买 nike

<分区>

我的第二个 FOR 循环在过程中间被自己跳过了。你能帮我解决这个问题吗?

我一直在尝试在网络上搜索,但没有一个对我有帮助。

int n = 9;
int arr[] = {10, 20, 20, 10, 10, 30, 50, 10, 20};

int temp = 0;
int skip[99];
int total = 0;
for (int i = 0; i < n; i++)
{
if (i == skip[i])
{
continue;
}
else
{
temp = arr[i];
for (int j = i+1; j<n - i; j++)
{
if (temp == arr[j])
{
total += 1;
skip[j] = j;
break;
}
else
{
continue;
}
}
}
}
cout << total;

结果应该是3,但是我得到的是2,因为在过程中间跳过了循环。

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