【NEEPU OJ】1040--Three Numbers

描述

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) * 9)) cout << i << " " << 2 * i << " " << 3 * i << endl;
    } //  上面要 * 9 因为没有初始化a数组全为0,若是 * 10 则最后一位不相等,不能通过
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值