public static void main(String[] args) {
int [] a={2,1,2,-5,6,10,34,9,10,10,33};
int count=0;
ArrayList<Integer> my=new ArrayList<Integer> () ;
for (int i = 0; i <a.length; i++) {
my.add(a[i]);
}
while((boolean) my.remove((Object)10)){
count++;
}
System.out.println(count);
}
------解决方案--------------------
C/C++ code
#include <stdio.h>
int main(int argc, char *argv[])
{
int a[]={2,1,2,-5,6,10,34,9,10,10,33};
int count = 0;
int b = sizeof(a)/sizeof(int);
int *p = a;
int *pp = &a[b];
int i = 0;
while(i < b)
{
if (a[i] == 10)
{
a[i] = *p;
p++;
count++;
}
i++;
}
printf("count:%d\n", count);
while(p < pp)
{
printf("%d ", *p);
p++;
}
return 0;
}
------解决方案--------------------
C/C++ code
int TrimNum(int arr[], int len, int num)
{
int total = 0, index = 0;
while (index < len)
{
if (arr[index] == num)
{
totoal++;
continue;
}
if (total > 0)
arr[index - total] = arr[index];
index++;
}
return total;
}