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;
}