题目大意:给定一个数组,若相邻的两个数之和为偶数,则将此两个数移除,通过这种方法将满足条件得数移除后数组还剩多少个数。

此题太水,不做解释。直接代码之:

#include <stdio.h>

int main()
{
    int n, i, num, tmp, a[100002];
    while(scanf("%d", &n)==1)
    {
        for(i=0,num=0; i<n; i++)
        {
            scanf("%d",&tmp);
            if(0 == i)
            {
                a[num++]=tmp;
            }
            else{
                if((tmp+a[num-1])%2 ==0 && num>0)
                {
                    num--;
                }
                else
                {
                    a[num++]=tmp;
                }
            }
        }
        printf("%d\n",num);
    }

    return 0;
}


相关文章:

  • 2021-12-31
  • 2021-08-09
  • 2021-05-19
  • 2021-09-16
  • 2021-06-17
猜你喜欢
  • 2022-02-21
  • 2021-06-30
  • 2022-12-23
  • 2021-08-05
  • 2021-08-14
  • 2021-09-29
  • 2021-08-27
相关资源
相似解决方案