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

      

  • 相关阅读:
    note 11 字典
    note10 元组
    hibernate环境搭建及操作
    JAVA中解决Filter过滤掉css,js,图片文件等问题
    过滤器
    MySQL存储过程(转)
    用java调用oracle存储过程总结(转)
    Oracle分页查询语句的写法(转)
    数据访问类的封装
    事务的特性及事务的隔离级别(转)
  • 原文地址:https://www.cnblogs.com/SutsuharaYuki/p/13718304.html
Copyright © 2020-2023  润新知