1010 Reports

http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=909

Reports

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


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,,anai denotes the type of the i-th report. ai=0 denotes a leaving school report and ai=1 denotes an entering school report.

1T100

3n50

0ai1
 
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 <iostream>
using namespace std;

int main(){
    int T;
    ios::sync_with_stdio(false);
    cin>>T;
    while(T--){
        int n,a[55]={0};
        cin>>n;
        bool flag=0;
        for(int i=0;i<n;i++)
            cin>>a[i];
        for(int i=1;i<n;i++)
            if(a[i]==a[i-1]){
                cout<<"NO"<<endl;
                flag=1;
                break;
            }   
        if(!flag)   cout<<"YES"<<endl;
    }            
    return 0;
}

  

原文地址:https://www.cnblogs.com/SutsuharaYuki/p/13718304.html