Write and Erase

Posted ylrwj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Write and Erase相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces - 1537E2 Erase and Extend (Hard Version)(扩展KMP-比较两个前缀无限循环后的字典序大小)

CH58xFLASH操作

C语言 write和read语句的基本用法

[RxJS] Implement RxJS `mergeMap` through inner Observables to Subscribe and Pass Values Through(代码片段

环境初始化 Build and Install the Apache Thrift IDL Compiler Install the Platform Development Tools(代码片段

项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde(代码片段