【CUGBACM15级BC第28场 A】hdu 5166 Missing number

xiaoxiao2021-02-27  206

Missing number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1178    Accepted Submission(s): 608 Problem Description There is a permutation without two numbers in it, and now you know what numbers the permutation has. Please find the two numbers it lose.   Input There is a number T shows there are T test cases below. ( T10 ) For each test case , the first line contains a integers n , which means the number of numbers the permutation has. In following a line , there are n distinct postive integers.( 1n1,000   )   Output For each case output two numbers , small number first.   Sample Input 2 3 3 4 5 1 1   Sample Output 1 2 2 3   给定一个排列,小yb不小心弄丢了这个排列中的两个数字,输入数据中给出的是小明现在手上有的序列,要求得丢失的那两个数列,并且按从小到大的顺序输出就好了;从给出的数据我们很容易就可以推断,这个所给的数列就是 1至n+2 #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; int a[1005]; int main() { int t; cin >> t; while (t--) { memset(a, 0, sizeof(a)); int n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; a[x]++; } int ans[2], s = 0; for (int i = 1; i < 1000 + 5; i++) { if (a[i] == 0) { ans[s] = i; s++; if (s == 2) { break; } } } cout << ans[0] << ' ' << ans[1] << endl; } return 0; }
转载请注明原文地址: https://www.6miu.com/read-11936.html

最新回复(0)