Missing number HDU5166
来源:互联网 发布:vb循环语句for next 编辑:程序博客网 时间:2024/04/30 18:20
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.( ) Output
For each case output two numbers , small number first. Sample Input
233 4 511
Sample Output
1 22 3 题意:给定一个全排列,但是这个全排列中失去了两个数,要你找出这两个数。思路:用数组把输入的数标记起来,都赋值为1,如果a[i]==1,就证明i没丢失,否则丢失了。代码:#include<iostream>#include<algorithm>#include<cstring>int const maxn=1010;int a[maxn];using namespace std;int main(){ int T,n; cin>>T; while(T<=10&&T>0&&T--) { memset(a,0,sizeof(a)); cin>>n; for(int i=0;i<n;i++) { int k; cin>>k; a[k]=1; } int flag=1; for(int i=1;i<=n+2;i++) if(!a[i]) { if(flag) {cout<<i<<' '; flag=0; } else cout<<i; } cout<<endl; } return 0;}
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
Output
For each case output two numbers , small number first.
Sample Input
233 4 511
Sample Output
1 22 3题意:给定一个全排列,但是这个全排列中失去了两个数,要你找出这两个数。思路:用数组把输入的数标记起来,都赋值为1,如果a[i]==1,就证明i没丢失,否则丢失了。代码:#include<iostream>#include<algorithm>#include<cstring>int const maxn=1010;int a[maxn];using namespace std;int main(){ int T,n; cin>>T; while(T<=10&&T>0&&T--) { memset(a,0,sizeof(a)); cin>>n; for(int i=0;i<n;i++) { int k; cin>>k; a[k]=1; } int flag=1; for(int i=1;i<=n+2;i++) if(!a[i]) { if(flag) {cout<<i<<' '; flag=0; } else cout<<i; } cout<<endl; } return 0;}
0 0
- Missing number HDU5166
- 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
- Android 支付宝 SDK 无法跳转到wap支付
- Oracle创建表空间和用户
- C++重载输出操作符
- 解决ubuntu侧边栏固定应用单击无反应的问题
- 浅谈C++多态性
- Missing number HDU5166
- Launcher3如何实现主菜单背景的透明度调整
- AOS应用基础平台-GIF图片教你如何把AOS打成war包发布
- Python 字符处理
- 优化临时表使用,SQL语句性能提升100倍
- 面向对象与面向过程
- Android报错记录
- 轻量级框架和重量级框架
- Android中WindowManager.LayoutParams类详解