Missing number

来源:互联网 发布:淘宝店旺铺是什么 编辑:程序博客网 时间:2024/05/16 08:09
Missing number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0



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. (T≤10 )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.(1≤n≤1,000 ) 
Output
For each case output two numbers , small number first. 
Sample Input
2
3
3 4 5
1

Sample Output
1 2

2 3

#include<iostream>#include<string.h>#include<algorithm>using namespace std;int main(){int T,i,a[1000];cin>>T;while(T--){memset(a,0,sizeof(a));int n,flag=0;int ji=0;cin>>n;for(i=0;i<n;i++)cin>>a[i];sort(a,a+n);if(a[0]>=3)cout<<1<<" "<<2<<endl;else if(a[0]==2){cout<<1<<" ";for(i=0;i<n-1;i++){if(a[i]+1<a[i+1]){cout<<a[i]+1<<endl;flag=1;break;}}if(flag==0)cout<<a[n-1]+1<<endl;}else if(a[0]==1){for(i=0;i<n-1;i++){                if(a[i]+1<a[i+1]){ji++;if(ji==1){cout<<a[i]+1<<" ";   a[i]++;    i--;}else if(ji==2){cout<<a[i]+1<<endl;break;}}}if(ji==0)cout<<a[n-1]+1<<" "<<a[n-1]+2<<endl;if(ji==1)cout<<a[n-1]+1<<endl;}}return 0;}


0 0
原创粉丝点击