2020ccpc网络赛1010 Reports

2020ccpc网络赛1010 Reports

Reports
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0

Problem Description
Because of Covid-19, Kanade needs to report every time when entering and leaving school. Now you want to check if Kanade’s reports on a certain day are correct.

A sequence of reports is correct if and only if there does not exist two consecutive and same reports.

Input
There are T test cases in this problem.

The first line has one integer T.

For every test case:

The first line has one integer n which denotes the number of times Kanade reported on a certain day.

The second line has n integers a1,a2,a3,⋯,an, ai denotes the type of the i-th report. ai=0 denotes a leaving school report and ai=1 denotes an entering school report.

1≤T≤100

3≤n≤50

0≤ai≤1

Output
For every test case, output "YES’’ if Kanade’s reports are correct, otherwise output "NO’’ (without quotes)

Sample Input
4
3
1 1 1
3
1 0 1
5
0 1 0 1 0
4
1 0 1 1

Sample Output
NO
YES
YES
NO

方法一源代码:

#include <stdio.h>

int main() {
int T,n,a[50],test;
scanf("%d",&T);
while (T–){
test=1;
scanf("%d",&n);
for (int i = 0; i <n ; ++i) {
scanf("%d",&a[i]);
}
for (int j = 0; j <n-1 ; ++j) {
if (a[j]+a[j+1]!=1){
test=0;
break;
}
}
if (test)
printf(“YES\n”);
else
printf(“NO\n”);
}
return 0;
}

方法二源代码:

#include
#include
#include
using namespace std;
int main() {
vector<vector > res;
vector ins;
int T, n, input;
int flag1, flag2;
flag1 = 0;
flag2 = 0;
cin >> T;
if (T < 1 || T>100) {
cout << “Input error” << endl;
return 0;
}
for (int i = 0; i < T; ++i) {
cin >> n;
if (n < 3 || n>50) {
cout << “Input error” << endl;
return 0;
}
for (int k = 0; k < n; ++k) {
cin >> input;
if (input != 0 && input != 1) {
cout << “Input error” << endl;
return 0;
}
ins.push_back(input);
}
res.push_back(ins);
ins.clear();
}
for (int i = 0; i < (int)res.size(); ++i) {
for (int k = 0; k < (int)res[i].size(); ++k) {
if (k == (int)res[i].size() - 1) {
cout << “YES” << endl;
break;
}
if (res[i][k] == 1) {
if (res[i][k+1] != 0) {
cout << “NO” << endl;
break;
}
}
else if (res[i][k+1] != 1) {
cout << “NO” << endl;
break;
}
}
}
system(“pause”);
return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值