[NOIP1998 普及组] 三连击
题目背景
本题为提交答案题,您可以写程序或手算在本机上算出答案后,直接提交答案文本,也可提交答案生成程序。
题目描述
将 1 , 2 , … , 9 1, 2, \ldots , 9 1,2,…,9 共 9 9 9 个数分成 3 3 3 组,分别组成 3 3 3 个三位数,且使这 3 3 3 个三位数构成 1 : 2 : 3 1 : 2 : 3 1:2:3 的比例,试求出所有满足条件的 3 3 3 个三位数。
输入格式
无
输出格式
若干行,每行 3 3 3 个数字。按照每行第 1 1 1 个数字升序排列。
样例 #1
样例输入 #1
无
样例输出 #1
192 384 576
* * *
...* * *
(剩余部分不予展示)
代码如下:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<istream>
#include<iomanip>
#include<ostream>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<fstream>
#include<stack>
#include<ctime>
#include<deque>
#include<queue>
#include <sstream>
#include <numeric>
#include <sstream>#pragma warning (disable:4996)int temp;
using namespace std;int fun(int a,int b,int c)
{int flag[10] = { 0 };while (a > 0){temp = a % 10;flag[temp] = 1;a /= 10;}while (b > 0){temp = b % 10;flag[temp] = 1;b /= 10;}while (c > 0){temp = c % 10;flag[temp] = 1;c /= 10;}if (flag[0] == 1)return 0;for (int i = 1; i <= 9; i++){if (flag[i] == 0)return 0;}return 1;
}int main() {int x;for(int i=1;i<=3;i++){for (int j = 1; j <= 9; j++) {for (int k = 1; k <= 9; k++) {if (i != j && i != k && j != k) {x=i * 100 + j * 10 + k;if (x * 2 <= 999) {if (x * 3 <= 999) {if (fun(x, x * 2, x * 3)==1)cout << x << " " << x * 2 << " " << x * 3 << endl;}}}}}}}