现在的位置: 首页 > 综合 > 正文

o.boj 1066 SPOJ

2013年04月01日 ⁄ 综合 ⁄ 共 1521字 ⁄ 字号 评论关闭

注:最近这一系列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;
}

抱歉!评论已关闭.