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
1
Sample Output
1 2
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
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
- Missing number
- Missing number
- Missing number
- Missing number
- Missing Number
- Missing Number
- Missing Number
- Missing Number.
- Missing Number
- Missing Number
- Missing Number
- Missing Number
- Missing Number
- Missing Number
- Missing Number
- Missing Number
- Missing Number
- Missing Number
- va_list、va_start、va_arg、va_end等利用宏定义实现可变参数
- oracle常用的查询语句
- Oracle CRS/GI 进程介绍
- [LeetCode] Longest Valid Parentheses 解题报告
- 算法导论学习之一步接一步笔记
- Missing number
- ORACLE权限管理调研笔记
- [LeetCode]154.Find Minimum in Rotated Sorted Array II
- windows驱动编程学习(2)--------第一个驱动 hello
- The Second--Static in java
- opencv学习测试代码笔记
- 用cocos2dx实现一个秒表级的计时器。
- CAAnimation
- IOS程序起始点分析