离散题目2

来源:互联网 发布:插画师dorami辞软件 编辑:程序博客网 时间:2024/06/05 18:11

离散题目2

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic

Problem Description

DaYu是一个喜欢看电影的好孩子,他的电脑里有成千上万部电影。因为某些不可描述的原因,他把这些电影以互不相同的编号命名(编号是数字且范围在(0,1000000)之间)。因为电影实在太多,他记不住自己已经看过了哪些电影。现在他把他看电影的记录给你,请你帮他检查一下他有没有看重复的电影。如果没有,输出“true”,否则输出“false”。

Input

第一行输入组数T(T<1000),每组的第一行输入他看的电影数量n(0 < n < 1000000),第二行输入n个数字,分别是每一部电影的编号。

Output

对于每组数据,如果没有重复的,那么输出true,否则输出false。

Example Input

251 2 3 4 551 2 3 4 4

Example Output

truefalse
代码:#include <bits/stdc++.h>using namespace std;int main(){int t;cin>>t;while(t--){int n;int a[1000005];cin>>n;for(int i = 0; i < n; i++){cin>>a[i];}sort(a, a+n);int flag = 1;for(int i = 0; i < n-1; i++){if(a[i] == a[i+1]){flag = 0;break;}}if(flag)cout<<"true"<<endl;else cout<<"false"<<endl;}return 0;}
原创粉丝点击