题解 P1407 【工资】
lqzhhh
·
·
题解
#include<bits/stdc++.h>
#define ll long long
#define For(i,a,b) for (int i=a;i<=b;i++)
#define Rep(i,a,b) for (int i=b;i>=a;i--)
using namespace std;
ll n,m,x,y,t;
inline ll read()//读入优化
{
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
int main()
{
n=read();
For(lqz,1,n)
{
t=1;
m=read();
x=read();
For(i,2,m)
{
y=read();
if(x==y)t++;//若相同t++
if(x!=y)t--;//若不相同则t--
if(t==0)x=y,t=1;//t为零时更换x
}
cout<<x<<endl;//输出最终的x值
}
return 0;
}