📜  TCS CodeVita 2019 年 7 月

📅  最后修改于: 2022-05-13 01:58:17.962000             🧑  作者: Mango

TCS CodeVita 2019 年 7 月

编程测试(Python)

1. 假设在 dd-mm-yyyy 发生了日食。现在,我们有兴趣计算下一次日食发生的日期。 (没解决

输入:

Input: The date in format dd-mm-yyyy
Output: Desired date in yyyy-mm-dd format
Constraints:
    It is guaranteed that given date is valid.
    01 <= dd <= 31
    01 <= mm <= 12
    1900 <= yy <= 2100

我觉得这里缺少一些细节。

2、根据投资金额、最终回报金额和投资期限,求出本次投资的简单收益率和年化收益率。

Input: 
1st line contains amount invested. 
2nd line contains amount returned. 
3rd line contains period of investment.

Output: 
1st line contains simple rate of return. 
2nd line contains annualized return. 
Output must be rounded off to up to 2 decimal places.
Python
import sys, os
amount_invested = float(raw_input())
final_amount = float(raw_input())
period = float(raw_input())
 
temp_val = ((final_amount - amount_invested)) / amount_invested
rate = ((final_amount - amount_invested) * 100.0) / amount_invested / period
annualized_return = round(((1 + temp_val) ** (1 / period) - 1) * 100.0, 2)
print "%.2f" % round(rate, 2)
print "%.2f" % annualized_return


Python
n = int(raw_input())
broker_rate = float(raw_input())
 
total_turnover = 0.0
for i in range(n):
    lst = raw_input().split()
    total_turnover += float(lst[0]) * float(lst[2])
fee = total_turnover * broker_rate
print "%.2f" % (fee / 100.0)


Sample input:
10000
20000
5

Sample output:
20.00
14.87

3. Sam 对市场和投资感兴趣。他经常买入新股,将非盈利股卖出一次。为了做同样的事情,他向向 Sam 收取一定金额的经纪人寻求帮助。了解 Sam 为特定交易向经纪人支付了多少费用。 (未解决 - 一些测试用例失败

Input:
1st line contains no. of stocks Sam deals with (N). 2nd line contains constant brokerage rate that the broker takes from Sam for every transaction (B).
The next lines will have stock details in the form: Volume or numbers of a stock, stock name, unit price of stock, bought/sold (B/S).

Output:
Total amount Sam pays to the broker. The output will be upto 2 decimal places and the value will be rounded off to DOWN.

Python

n = int(raw_input())
broker_rate = float(raw_input())
 
total_turnover = 0.0
for i in range(n):
    lst = raw_input().split()
    total_turnover += float(lst[0]) * float(lst[2])
fee = total_turnover * broker_rate
print "%.2f" % (fee / 100.0)
Sample input:
2
0.5
1 S1 100 B
2 S2 110 S

Sample output:
1.05

总的来说,测试并不太难,但需要一些研究来理解问题。