版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34072526/article/details/86567838
描述
Oh, yes! Alice likes math very much. So, she is studying another problem.
Divide 1, 2, …, 9 into three groups, and combine them into three 3-digit numbers, whose ratio is 1:2:3. Please calculate all three 3-digit numbers meeting the condition.
For example: Three 3-digit numbers 192, 384, 576 meet the condition above.
输入
No input.
输出
Output all solutions meeting the condition. Output each group of numbers in a line, and a space character between each number.
Output three numbers in each group ascendingly. Sort each group by the first number of it ascendingly.
输入样例 1
No Input.
输出样例 1
There is only one solution. So, there is no sample output.
来源
NEEPU 13th ACM
代码
#include <iostream>
#include <algorithm>
#include <cstring>//为了使用memcmp函数
using namespace std;
int main(){
int i,j,t;
int a[10];
int num[10]={1,2,3,4,5,6,7,8,9};
for(i=192;i<328;i++){//这里的数据是优化得来的
t=1;
for(j=0;j<=6;j+=3){
a[j]=t*i/100;
a[j+1]=t*i/10%10;
a[j+2]=t*i%10;
t++;
}
sort(a,a+9);
if(!memcmp(a,num,sizeof(int)*10)) cout<<i<<" "<<2*i<<" "<<3*i<<endl;
}
return 0;
}