码迷,mamicode.com
首页 > 其他好文 > 详细

Write and Erase

时间:2019-04-29 20:56:37      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:following   偶数   hat   ase   format   return   process   turn   namespace   

You are playing the following game with Joisino.

  • Initially, you have a blank sheet of paper.
  • Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
  • Then, you are asked a question: How many numbers are written on the sheet now?

The numbers announced by Joisino are given as A1,…,AN in the order she announces them. How many numbers will be written on the sheet at the end of the game?

Constraints

 

  • 1≤N≤100000
  • 1≤Ai≤1000000000(=109)
  • All input values are integers.

Input

 

Input is given from Standard Input in the following format:

N
A1
:
AN

Output

 

Print how many numbers will be written on the sheet at the end of the game.

Sample Input 1

 

3
6
2
6

Sample Output 1

 

1

The game proceeds as follows:

  • 6 is not written on the sheet, so write 6.

  • 2 is not written on the sheet, so write 2.

  • 6 is written on the sheet, so erase 6.

Thus, the sheet contains only 2 in the end. The answer is 1.

Sample Input 2

 

4
2
5
5
2

Sample Output 2

 

0

It is possible that no number is written on the sheet in the end.

Sample Input 3

 

6
12
22
16
22
18
12

Sample Output 3

 

2



该题就是判断一个数出现的次数,偶数为0,奇数+1;
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long a[1000010];
int main()
{
    int n,x=1,ans=0;//x表示一个数出现的次数,赋值1 
    cin>>n;
    for(int i=0;i<n;i++)
       cin>>a[i];
    sort(a,a+n);//先排序,更方便判断奇偶 
    for(int i=1;i<n;i++)
    {
        if(a[i]==a[i-1])//出现相同的数,x+1然后mod2 
          x=(x+1)%2;
        else
        {
            ans+=x;//单独的一个数,ans+1,x重新赋值为1,进行循环 
            x=1;
        }      
    }
    if(x%2)//再次判断 ,若不为0,则ans+1 
      ans++;
    cout<<ans<<endl;
    return 0;
} 

 

Write and Erase

标签:following   偶数   hat   ase   format   return   process   turn   namespace   

原文地址:https://www.cnblogs.com/ylrwj/p/10792504.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!