2020中国大学生程序设计竞赛(CCPC) - 网络选拔赛 1010 Reports

2020中国大学生程序设计竞赛(CCPC) - 网络选拔赛 1010 Reports(签到题)
2020中国大学生程序设计竞赛(CCPC) - 网络选拔赛 1010 Reports
如果相邻的任意两个数相同的话,则输出NO,反之输出YES。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
//#define int ll
#define INF 0x3f3f3f3f
using namespace std;
int read()
{
	int w = 1, s = 0;
	char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0';    ch = getchar(); }
	return s * w;
}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
int main()
{
    int t = read();
    while(t--) {
        int n = read();
        int a = read();
        bool flag = false;
        int tmp;
        n--;
        while(n--) {
            tmp = a;
            a = read();
            if(tmp == a) {
                flag = true;
            }
        }
        if (flag)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-- != 0) {
            int n = sc.nextInt();
            int a = sc.nextInt();
            boolean flag = false;
            int tmp;
            n--;
            while(n-- != 0) {
                tmp = a;
                a = sc.nextInt();
                if (tmp == a) {
                    flag = true;
                }
            }
            if(flag)
                System.out.println("NO");
            else
                System.out.println("YES");
        }
    }
}

©️2020 CSDN 皮肤主题: 黑客帝国 设计师:上身试试 返回首页