o.boj 1066 SPOJ

这是一道经典的数学问题,讲述了如何从九个不同的正整数中找出七个数,使其总和等于100。题目背景设定在一个有趣的童话故事中,通过数学的方式帮助Snow White辨别出真正的七个小矮人。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

注:最近这一系列ACM的内容,都是2年多之前的代码,自己回顾一下。
PATULJCI
 
Submit: 1156   Accepted:704
Time Limit: 1000MS  Memory Limit: 65535K

Description

Every day, while the dwarves are busy in the mines, Snow White prepares dinner for them; seven chairs, seven plates, seven forks and seven knives for seven hungry dwarves. One day nine dwarves came from the mines instead of seven (nobody knows how or why), each of them claiming to be one of Snow White's seven dwarves. Luckily, each dwarf wears a hat with a positive integer less than 100 written on it. Snow White, a famous mathematician, realised long ago that the sum of numbers on the hats of her seven dwarves was exactly 100. Write a program which determines which dwarves are legit, i.e. pick seven of nine numbers that add to 100.

Input

There are 9 lines of input. Each contains an integer between 1 and 99 (inclusive). All of the numbers will be distinct. Note: The test data will be such that the solution is unique.

Output

Your program must produce exactly seven lines of output – the numbers on the hats of Snow White's seven dwarves. Output the numbers in any order.

Sample Input 7

8

10

13

15

19

20

23

25

Sample Output 7

8

10

13

19

20

23



Source Croatian Open Competition in Informatics

 
七个小矮人突然变成九个小矮人了,但真正的七个小矮人头上的编号加起来刚好是100,计算出哪些是真正的小矮人。
方法很简单,先算出9个数之和,减100,则为多出来那两个数的和,然后计算是哪两个数之和。

模拟题
#include <stdio.h>

main()
{
    char time[6];
    int N, num, ht, mt, money = 0;
    
    scanf("%d", &N);
    
    while (N--)
    {
        scanf("%s", time);
        
        ht = (time[0] - 48) * 10 + time[1] - 48;
        mt = (time[3] - 48) * 10 + time[4] - 48;
        
        scanf("%d", &num);
        
        if (ht >= 7 && ht < 19)
        {
            if ((ht + (mt + num)/60) == 19)
                money += ((mt + num)%60*5 + (60-mt)*10);                
            else
                money += (num * 10);
        }
        else
        {
            if ((ht + (mt + num)/60) == 7)
                money += (((mt + num)%60)*10 + (60 - mt)*5);
            else
                money += (num * 5);
        }
    }
    
    printf("%d\n", money);
    // system("pause");
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值