作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
<分区>
我的第二个 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
,因为在过程中间跳过了循环。
我是一名优秀的程序员,十分优秀!