2015 HUAS Provincial Select Contest #2 A 题目: 题目大意:输入N连续个数,求它的最小的两个数。 解题思路:用一个数组存储这N个数,再用另个数组存储1—N+2的连续数,再两个数组比较,输出缺了的两项。 代码:
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 shows there are test cases below. (
)
For each test case , the first line contains a integers , which means the number of numbers the permutation has. In following a line , there are distinct postive integers.(
)
For each test case , the first line contains a integers , which means the number of numbers the permutation has. In following a line , there are distinct postive integers.(
Output
For each case output two numbers , small number first.
题目大意:输入N连续个数,求它的最小的两个数。
解题思路:用一个数组存储这N个数,再用另个数组存储1—N+2的连续数,再两个数组比较,输出缺了的两项。
代码:
1 #include<iostream> 2 #include<cstdio> 3 #define maxn 1010 4 using namespace std; 5 int main() 6 { 7 int T; 8 cin >> T; 9 if(T<=10) 10 { 11 while (T--) 12 { 13 int n, a[maxn],b[maxn] ,i,d; 14 cin >> n; 15 if(n>=1&&n<=1000) 16 { 17 d=0; 18 for (i = 0; i <n; i++) 19 cin >> a[i]; 20 for(i=0;i<n+2;i++) 21 b[i]=i+1; 22 23 for(i=0;i<n;i++) 24 { 25 for(int j=0;j<n+2;j++) 26 { 27 if(a[i]==b[j]) 28 b[j]=0; 29 } 30 } 31 for(i=0;i<n+2;i++) 32 { 33 if(b[i]!=0) 34 { 35 d++; 36 if(d==2) 37 printf("%d ",b[i]); 38 else printf("%d ",b[i]); 39 40 } 41 } 42 } 43 } 44 } 45 return 0; 46 }