语言考试练习题_排列 oj21
来源:互联网 发布:布艺沙发 知乎 编辑:程序博客网 时间:2024/04/28 21:36
语言考试练习题_排列
发布时间: 2017年5月25日 19:57 最后更新: 2017年5月26日 00:08 时间限制: 1000ms 内存限制: 128M
有4个互不相同的数字,输出由其中三个不重复数字组成的排列。
4个整数。
所有排列。
复制
1 2 3 4
1 2 31 3 22 1 32 3 13 1 23 2 11 2 41 4 22 1 42 4 14 1 24 2 11 3 41 4 33 1 43 4 14 1 34 3 12 3 42 4 33 2 43 4 24 2 34 3 2
#include <algorithm>#include <cstdio>#include <vector> #include <iostream> using namespace std;int main(){int a[4] = { 0 };for (int i = 0; i < 4; i++)scanf("%d", &a[i]);vector<int> ans1,ans2,ans3,ans4;sort(a, a + 4);do{if (a[0] == 0)continue;ans1.push_back(a[0] * 100 + a[1] * 10 + a[2] * 1);} while (next_permutation(a, a + 3));int tmp[3];tmp[0] = a[0], tmp[1] = a[1], tmp[2] = a[3];do{if (tmp[0] == 0)continue;ans2.push_back(tmp[0] * 100 + tmp[1] * 10 + tmp[2] * 1);} while (next_permutation(tmp, tmp + 3));tmp[1] = a[2];do{if (tmp[0] == 0)continue;ans3.push_back(tmp[0] * 100 + tmp[1] * 10 + tmp[2] * 1);} while (next_permutation(tmp, tmp + 3));tmp[0] = a[1];do{if (tmp[0] == 0)continue;ans4.push_back(tmp[0] * 100 + tmp[1] * 10 + tmp[2] * 1);} while (next_permutation(tmp, tmp + 3));for (int i = 0; i < ans1.size(); i++)cout << ans1[i] / 100 << " " << ans1[i]%100/10<<" "<<ans1[i]%10<< endl;for (int i = 0; i < ans2.size(); i++)cout << ans2[i] / 100 << " " << ans2[i] % 100 / 10 << " " << ans2[i] % 10 << endl;for (int i = 0; i < ans3.size(); i++)cout << ans3[i] / 100 << " " << ans3[i] % 100 / 10 << " " << ans3[i] % 10 << endl;for (int i = 0; i < ans4.size(); i++)cout << ans4[i] / 100 << " " << ans4[i] % 100 / 10 << " " << ans4[i] % 10 << endl;return 0;}
阅读全文
0 0
- 语言考试练习题_排列 oj21
- 1004: C语言考试练习题_排列
- C语言考试练习题_排列
- 1412202059-hpu-1005:C语言考试练习题_排列
- hpuoj 1005: C语言考试练习题_排列【dfs】
- 1004:C语言考试练习题-排列
- 1412202035-hpu-1003:C语言考试练习题_一元二次方程
- 1412202049-hpu-1004:C语言考试练习题_保留字母
- 1113: C语言考试练习题_保留字母
- 问题 A: C语言考试练习题_一元二次方程
- OJ21
- NEUQ OJ 1131: C语言考试练习题_一元二次方程 描述
- Objective-c语言_数组练习题1
- Objective-c语言_数组练习题2:
- Objective-C语言_数组练习题
- Objective-c语言_练习题3
- Objective-c语言_练习题3
- 1003:C语言考试练习题—保留字母
- CentOS 6下的FTP服务器搭建
- Fire!
- POJ 3666-Making the Grade (DP+离散化)
- UVA673 Parentheses Balance【堆栈+输入流】
- http://blog.csdn.net/xu__cg/article/details/52901464
- 语言考试练习题_排列 oj21
- HDU-1021-Fibonacci Again
- 【Kmp求既是前缀又是后缀的子串】POJ
- OpenGL MFC单文档 实现轨迹球
- HDU 2049 不容易系列之(4)——考新郎
- 关于python GUI 多线程编程注意事项
- [leetcode]227. Basic Calculator II
- HDU 6044& 2017年多校训练第一场 1012题
- POJ 2947 Widget Factory(高斯消元)