飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 2755|回复: 0

[C/C++] 算法入门题 9-1

[复制链接]
  • TA的每日心情
    开心
    2024-12-6 17:12
  • 签到天数: 6 天

    [LV.2]偶尔看看I

    发表于 2009-8-31 00:27:41 | 显示全部楼层 |阅读模式

    1. 第一题:
    2. Elevator
    3. Problem Description
    4. The highest building in our city has only one elevator. A request list is made
    5. up with N positive numbers. The numbers denote at which floors the elevator
    6. will stop, in specified order. It costs 6 seconds to move the elevator up one
    7. floor, and 4 seconds to move down one floor. The elevator will stay for 5
    8. seconds at each stop.

    9. For a given request list, you are to compute the total time spent to fulfill
    10. the requests on the list. The elevator is on the 0th floor at the beginning
    11. and does not have to return to the ground floor when the requests are fulfilled.


    12. Input
    13. There are multiple test cases. Each case contains a positive integer N, followed
    14. by N positive numbers. All the numbers in the input are less than 100. A test
    15. case with N = 0 denotes the end of input. This test case is not to be processed.


    16. Output
    17. Print the total time on a single line for each test case.


    18. Sample Input
    19. 1 2
    20. 3 2 3 1
    21. 0


    22. Sample Output
    23. 17
    24. 41



    25. 第二题 hdu 1020
    26. Encoding
    27. Problem Description
    28. Given a string containing only 'A' - 'Z', we could encode it using the following method:

    29. 1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.

    30. 2. If the length of the sub-string is 1, '1' should be ignored.


    31. Input
    32. The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 10000.


    33. Output
    34. For each test case, output the encoded string in a line.


    35. Sample Input
    36. 2
    37. ABC
    38. ABBCCC


    39. Sample Output
    40. ABC
    41. A2B3C
    复制代码
    PYG19周年生日快乐!
    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

    快速回复 返回顶部 返回列表